mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-31 03:00:05 +00:00
Changes to Image::BitmapData constructors, replacing the bool with a more explicit enum for the read/write mode. Some win32 dLL declarator changes. Android work. Small Quicktime fix.
This commit is contained in:
parent
1d215fa865
commit
3dfbb0d713
37 changed files with 1216 additions and 431 deletions
|
|
@ -31,10 +31,16 @@ import android.graphics.*;
|
|||
|
||||
//==============================================================================
|
||||
public class ComponentPeerView extends View
|
||||
implements View.OnFocusChangeListener
|
||||
{
|
||||
public ComponentPeerView (Context context)
|
||||
public ComponentPeerView (Context context, boolean opaque_)
|
||||
{
|
||||
super (context);
|
||||
opaque = opaque_;
|
||||
setFocusable (true);
|
||||
setFocusableInTouchMode (true);
|
||||
setOnFocusChangeListener (this);
|
||||
requestFocus();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -46,6 +52,14 @@ public class ComponentPeerView extends View
|
|||
handlePaint (canvas);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpaque()
|
||||
{
|
||||
return opaque;
|
||||
}
|
||||
|
||||
private boolean opaque;
|
||||
|
||||
//==============================================================================
|
||||
private native void handleMouseDown (float x, float y, long time);
|
||||
private native void handleMouseDrag (float x, float y, long time);
|
||||
|
|
@ -70,6 +84,7 @@ public class ComponentPeerView extends View
|
|||
@Override
|
||||
protected void onSizeChanged (int w, int h, int oldw, int oldh)
|
||||
{
|
||||
viewSizeChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -77,16 +92,33 @@ public class ComponentPeerView extends View
|
|||
{
|
||||
}
|
||||
|
||||
private native void viewSizeChanged();
|
||||
|
||||
@Override
|
||||
public void onFocusChange (View v, boolean hasFocus)
|
||||
{
|
||||
if (v == this)
|
||||
focusChanged (hasFocus);
|
||||
}
|
||||
|
||||
private native void focusChanged (boolean hasFocus);
|
||||
|
||||
public void setViewName (String newName)
|
||||
{
|
||||
}
|
||||
|
||||
public boolean isVisible()
|
||||
{
|
||||
return true;
|
||||
return getVisibility() == VISIBLE;
|
||||
}
|
||||
|
||||
public void setVisible (boolean b)
|
||||
{
|
||||
setVisibility (b ? VISIBLE : INVISIBLE);
|
||||
}
|
||||
|
||||
public boolean containsPoint (int x, int y)
|
||||
{
|
||||
return true; //xxx needs to check overlapping views
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,11 +27,16 @@ package com.juce;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.content.*;
|
||||
import android.view.*;
|
||||
import android.content.Context;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Display;
|
||||
import android.view.WindowManager;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.text.ClipboardManager;
|
||||
import com.juce.ComponentPeerView;
|
||||
|
||||
|
||||
//==============================================================================
|
||||
public class JuceAppActivity extends Activity
|
||||
{
|
||||
|
|
@ -106,9 +111,9 @@ public class JuceAppActivity extends Activity
|
|||
//==============================================================================
|
||||
private ViewHolder viewHolder;
|
||||
|
||||
public ComponentPeerView createNewView()
|
||||
public ComponentPeerView createNewView (boolean opaque)
|
||||
{
|
||||
ComponentPeerView v = new ComponentPeerView (this);
|
||||
ComponentPeerView v = new ComponentPeerView (this, opaque);
|
||||
viewHolder.addView (v);
|
||||
return v;
|
||||
}
|
||||
|
|
@ -123,6 +128,8 @@ public class JuceAppActivity extends Activity
|
|||
public ViewHolder (Context context)
|
||||
{
|
||||
super (context);
|
||||
setDescendantFocusability (ViewGroup.FOCUS_AFTER_DESCENDANTS);
|
||||
setFocusable (false);
|
||||
}
|
||||
|
||||
protected void onLayout (boolean changed, int left, int top, int right, int bottom)
|
||||
|
|
@ -130,6 +137,11 @@ public class JuceAppActivity extends Activity
|
|||
}
|
||||
}
|
||||
|
||||
public void excludeClipRegion (android.graphics.Canvas canvas, float left, float top, float right, float bottom)
|
||||
{
|
||||
canvas.clipRect (left, top, right, bottom, android.graphics.Region.Op.DIFFERENCE);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
public String getClipboardContent()
|
||||
{
|
||||
|
|
@ -142,4 +154,97 @@ public class JuceAppActivity extends Activity
|
|||
ClipboardManager clipboard = (ClipboardManager) getSystemService (CLIPBOARD_SERVICE);
|
||||
clipboard.setText (newText);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
/*class PathGrabber extends Path
|
||||
{
|
||||
public PathGrabber()
|
||||
{
|
||||
pathString = new StringBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPath (Path src)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPath (Path src, float dx, float dy)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
pathString.append ('c');
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moveTo (float x, float y)
|
||||
{
|
||||
pathString.append ('m');
|
||||
pathString.append (String.valueOf (x));
|
||||
pathString.append (String.valueOf (y));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lineTo (float x, float y)
|
||||
{
|
||||
pathString.append ('l');
|
||||
pathString.append (String.valueOf (x));
|
||||
pathString.append (String.valueOf (y));
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
|
||||
@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 "";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -127,8 +127,14 @@ public:
|
|||
|
||||
bool getOutlineForGlyph (int glyphNumber, Path& destPath)
|
||||
{
|
||||
// TODO
|
||||
return false;
|
||||
LocalRef<jstring> s ((jstring) android.activity.callObjectMethod (android.createPathForGlyph, paint.get(), (jchar) glyphNumber));
|
||||
|
||||
if (s == 0)
|
||||
return false;
|
||||
|
||||
const String ourString (juceString (s));
|
||||
destPath.restoreFromString (ourString);
|
||||
return ourString.isNotEmpty();
|
||||
}
|
||||
|
||||
GlobalRef typeface, paint;
|
||||
|
|
|
|||
|
|
@ -27,22 +27,141 @@
|
|||
// compiled on its own).
|
||||
#if JUCE_INCLUDED_FILE
|
||||
|
||||
//==============================================================================
|
||||
class AndroidImage : public Image::SharedImage
|
||||
{
|
||||
public:
|
||||
//==============================================================================
|
||||
AndroidImage (const int width_, const int height_, const bool clearImage)
|
||||
: Image::SharedImage (Image::ARGB, width_, height_)
|
||||
{
|
||||
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_)
|
||||
: Image::SharedImage (Image::ARGB, width_, height_),
|
||||
bitmap (bitmap_)
|
||||
{
|
||||
}
|
||||
|
||||
~AndroidImage()
|
||||
{
|
||||
bitmap.callVoidMethod (android.recycle);
|
||||
}
|
||||
|
||||
Image::ImageType getType() const { return Image::NativeImage; }
|
||||
LowLevelGraphicsContext* createLowLevelContext();
|
||||
|
||||
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.dataReleaser = new CopyHandler (*this, bm, x, y, mode);
|
||||
}
|
||||
|
||||
SharedImage* clone()
|
||||
{
|
||||
JNIEnv* env = getEnv();
|
||||
jobject mode = env->GetStaticObjectField (android.bitmapConfigClass, android.ARGB_8888);
|
||||
GlobalRef newCopy (bitmap.callObjectMethod (android.bitmapCopy, mode, true));
|
||||
env->DeleteLocalRef (mode);
|
||||
|
||||
return new AndroidImage (width, height, newCopy);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
GlobalRef bitmap;
|
||||
|
||||
private:
|
||||
class CopyHandler : public Image::BitmapData::BitmapDataReleaser
|
||||
{
|
||||
public:
|
||||
CopyHandler (AndroidImage& owner_, Image::BitmapData& bitmapData_,
|
||||
const int x_, const int y_, const Image::BitmapData::ReadWriteMode mode_)
|
||||
: owner (owner_), bitmapData (bitmapData_), mode (mode_), x (x_), y (y_)
|
||||
{
|
||||
JNIEnv* env = getEnv();
|
||||
|
||||
intArray = env->NewIntArray (bitmapData.width * bitmapData.height);
|
||||
|
||||
if (mode != Image::BitmapData::writeOnly)
|
||||
owner_.bitmap.callVoidMethod (android.getPixels, intArray, 0, bitmapData.width, x_, y_,
|
||||
bitmapData.width, bitmapData.height);
|
||||
|
||||
bitmapData.data = (uint8*) env->GetIntArrayElements (intArray, 0);
|
||||
|
||||
if (mode != Image::BitmapData::writeOnly)
|
||||
{
|
||||
for (int yy = 0; yy < bitmapData.height; ++yy)
|
||||
{
|
||||
PixelARGB* p = (PixelARGB*) bitmapData.getLinePointer (yy);
|
||||
|
||||
for (int xx = 0; xx < bitmapData.width; ++xx)
|
||||
p[xx].premultiply();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~CopyHandler()
|
||||
{
|
||||
JNIEnv* env = getEnv();
|
||||
|
||||
if (mode != Image::BitmapData::readOnly)
|
||||
{
|
||||
for (int yy = 0; yy < bitmapData.height; ++yy)
|
||||
{
|
||||
PixelARGB* p = (PixelARGB*) bitmapData.getLinePointer (yy);
|
||||
|
||||
for (int xx = 0; xx < bitmapData.width; ++xx)
|
||||
p[xx].unpremultiply();
|
||||
}
|
||||
}
|
||||
|
||||
env->ReleaseIntArrayElements (intArray, (jint*) bitmapData.data, 0);
|
||||
|
||||
if (mode != Image::BitmapData::readOnly)
|
||||
owner.bitmap.callVoidMethod (android.setPixels, intArray, 0, bitmapData.width, x, y,
|
||||
bitmapData.width, bitmapData.height);
|
||||
|
||||
env->DeleteLocalRef (intArray);
|
||||
}
|
||||
|
||||
private:
|
||||
AndroidImage& owner;
|
||||
Image::BitmapData& bitmapData;
|
||||
jintArray intArray;
|
||||
const Image::BitmapData::ReadWriteMode mode;
|
||||
const int x, y;
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CopyHandler);
|
||||
};
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AndroidImage);
|
||||
};
|
||||
|
||||
Image::SharedImage* Image::SharedImage::createNativeImage (PixelFormat format, int width, int height, bool clearImage)
|
||||
{
|
||||
if (format == Image::SingleChannel)
|
||||
return createSoftwareImage (format, width, height, clearImage);
|
||||
else
|
||||
return new AndroidImage (width, height, clearImage);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
class AndroidLowLevelGraphicsContext : public LowLevelGraphicsContext
|
||||
{
|
||||
public:
|
||||
AndroidLowLevelGraphicsContext (const GlobalRef& canvas_)
|
||||
AndroidLowLevelGraphicsContext (jobject canvas_)
|
||||
: canvas (canvas_),
|
||||
currentState (new SavedState())
|
||||
{
|
||||
setFill (Colours::black);
|
||||
}
|
||||
|
||||
~AndroidLowLevelGraphicsContext()
|
||||
{
|
||||
}
|
||||
|
||||
bool isVectorDevice() const { return false; }
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -68,11 +187,19 @@ public:
|
|||
|
||||
bool clipToRectangleList (const RectangleList& clipRegion)
|
||||
{
|
||||
return canvas.callBooleanMethod (android.clipRegion, createRegion (getEnv(), clipRegion).get());
|
||||
RectangleList excluded (getClipBounds());
|
||||
excluded.subtract (clipRegion);
|
||||
|
||||
const int numRects = excluded.getNumRectangles();
|
||||
|
||||
for (int i = 0; i < numRects; ++i)
|
||||
excludeClipRectangle (excluded.getRectangle(i));
|
||||
}
|
||||
|
||||
void excludeClipRectangle (const Rectangle<int>& r)
|
||||
{
|
||||
android.activity.callVoidMethod (android.excludeClipRegion, canvas.get(),
|
||||
(float) r.getX(), (float) r.getY(), (float) r.getRight(), (float) r.getBottom());
|
||||
}
|
||||
|
||||
void clipToPath (const Path& path, const AffineTransform& transform)
|
||||
|
|
@ -82,6 +209,7 @@ public:
|
|||
|
||||
void clipToImageAlpha (const Image& sourceImage, const AffineTransform& transform)
|
||||
{
|
||||
// TODO xxx
|
||||
}
|
||||
|
||||
bool clipRegionIntersects (const Rectangle<int>& r)
|
||||
|
|
@ -117,10 +245,12 @@ public:
|
|||
|
||||
void setOpacity (float newOpacity)
|
||||
{
|
||||
currentState->setAlpha (newOpacity);
|
||||
}
|
||||
|
||||
void setInterpolationQuality (Graphics::ResamplingQuality quality)
|
||||
{
|
||||
// TODO xxx
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -139,6 +269,60 @@ public:
|
|||
|
||||
void drawImage (const Image& sourceImage, const AffineTransform& transform, bool fillEntireClipAsTiles)
|
||||
{
|
||||
AndroidImage* androidImage = dynamic_cast <AndroidImage*> (sourceImage.getSharedImage());
|
||||
|
||||
if (androidImage != 0)
|
||||
{
|
||||
JNIEnv* env = getEnv();
|
||||
canvas.callVoidMethod (android.drawBitmap, androidImage->bitmap.get(),
|
||||
createMatrix (env, transform).get(), getImagePaint());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (transform.isOnlyTranslation())
|
||||
{
|
||||
JNIEnv* env = getEnv();
|
||||
|
||||
Image::BitmapData bm (sourceImage, Image::BitmapData::readOnly);
|
||||
|
||||
jintArray imageData = env->NewIntArray (bm.width * bm.height);
|
||||
jint* dest = env->GetIntArrayElements (imageData, 0);
|
||||
|
||||
if (dest != 0)
|
||||
{
|
||||
const uint8* srcLine = bm.getLinePointer (0);
|
||||
jint* dstLine = dest;
|
||||
|
||||
for (int y = 0; y < bm.height; ++y)
|
||||
{
|
||||
switch (bm.pixelFormat)
|
||||
{
|
||||
case Image::ARGB: copyPixels (dstLine, (PixelARGB*) srcLine, bm.width, bm.pixelStride); break;
|
||||
case Image::RGB: copyPixels (dstLine, (PixelRGB*) srcLine, bm.width, bm.pixelStride); break;
|
||||
case Image::SingleChannel: copyPixels (dstLine, (PixelAlpha*) srcLine, bm.width, bm.pixelStride); break;
|
||||
default: jassertfalse; break;
|
||||
}
|
||||
|
||||
srcLine += bm.lineStride;
|
||||
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);
|
||||
env->DeleteLocalRef (imageData);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
saveState();
|
||||
addTransform (transform);
|
||||
drawImage (sourceImage, AffineTransform::identity, fillEntireClipAsTiles);
|
||||
restoreState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void drawLine (const Line <float>& line)
|
||||
|
|
@ -215,10 +399,12 @@ public:
|
|||
|
||||
void beginTransparencyLayer (float opacity)
|
||||
{
|
||||
// TODO xxx
|
||||
}
|
||||
|
||||
void endTransparencyLayer()
|
||||
{
|
||||
// TODO xxx
|
||||
}
|
||||
|
||||
class SavedState
|
||||
|
|
@ -240,6 +426,12 @@ public:
|
|||
fillType = newType;
|
||||
}
|
||||
|
||||
void setAlpha (float alpha)
|
||||
{
|
||||
fillNeedsUpdate = true;
|
||||
fillType.colour = fillType.colour.withAlpha (alpha);
|
||||
}
|
||||
|
||||
jobject getPaint()
|
||||
{
|
||||
if (fillNeedsUpdate)
|
||||
|
|
@ -299,6 +491,7 @@ public:
|
|||
tileMode);
|
||||
}
|
||||
|
||||
env->DeleteLocalRef (tileMode);
|
||||
env->DeleteLocalRef (coloursArray);
|
||||
env->DeleteLocalRef (positionsArray);
|
||||
|
||||
|
|
@ -309,6 +502,7 @@ public:
|
|||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -330,11 +524,22 @@ public:
|
|||
paint.callObjectMethod (android.setTypeface, atf->typeface.get());
|
||||
paint.callVoidMethod (android.setTextSize, font.getHeight());
|
||||
}
|
||||
|
||||
fillNeedsUpdate = true;
|
||||
paint.callVoidMethod (android.setAlpha, (jint) fillType.colour.getAlpha());
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
jobject getImagePaint()
|
||||
{
|
||||
jobject p = getPaint();
|
||||
paint.callVoidMethod (android.setAlpha, (jint) fillType.colour.getAlpha());
|
||||
fillNeedsUpdate = true;
|
||||
return p;
|
||||
}
|
||||
|
||||
FillType fillType;
|
||||
Font font;
|
||||
GlobalRef paint;
|
||||
|
|
@ -347,10 +552,8 @@ private:
|
|||
ScopedPointer <SavedState> currentState;
|
||||
OwnedArray <SavedState> stateStack;
|
||||
|
||||
jobject getCurrentPaint() const
|
||||
{
|
||||
return currentState->getPaint();
|
||||
}
|
||||
jobject getCurrentPaint() const { return currentState->getPaint(); }
|
||||
jobject getImagePaint() const { return currentState->getImagePaint(); }
|
||||
|
||||
static const LocalRef<jobject> createPath (JNIEnv* env, const Path& path)
|
||||
{
|
||||
|
|
@ -424,8 +627,24 @@ private:
|
|||
return col.getARGB();
|
||||
}
|
||||
|
||||
template <class PixelType>
|
||||
static void copyPixels (jint* const dest, const PixelType* src, const int width, const int pixelStride) throw()
|
||||
{
|
||||
for (int x = 0; x < width; ++x)
|
||||
{
|
||||
dest[x] = src->getUnpremultipliedARGB();
|
||||
src = addBytesToPointer (src, pixelStride);
|
||||
}
|
||||
}
|
||||
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AndroidLowLevelGraphicsContext);
|
||||
};
|
||||
|
||||
LowLevelGraphicsContext* AndroidImage::createLowLevelContext()
|
||||
{
|
||||
jobject canvas = getEnv()->NewObject (android.canvasClass, android.canvasBitmapConstructor, bitmap.get());
|
||||
return new AndroidLowLevelGraphicsContext (canvas);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -29,31 +29,14 @@
|
|||
|
||||
|
||||
//==============================================================================
|
||||
void MessageManager::doPlatformSpecificInitialisation()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void MessageManager::doPlatformSpecificShutdown()
|
||||
{
|
||||
|
||||
}
|
||||
void MessageManager::doPlatformSpecificInitialisation() {}
|
||||
void MessageManager::doPlatformSpecificShutdown() {}
|
||||
|
||||
//==============================================================================
|
||||
bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
|
||||
{
|
||||
// TODO
|
||||
|
||||
/*
|
||||
The idea here is that this will check the system message queue, pull off a
|
||||
message if there is one, deliver it, and return true if a message was delivered.
|
||||
If the queue's empty, return false.
|
||||
|
||||
If the message is one of our special ones (i.e. a Message object being delivered,
|
||||
this must call MessageManager::getInstance()->deliverMessage() to deliver it
|
||||
|
||||
|
||||
*/
|
||||
Logger::outputDebugString ("*** Modal loops are not possible in Android!! Exiting...");
|
||||
exit (1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -61,14 +44,16 @@ bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages
|
|||
//==============================================================================
|
||||
bool juce_postMessageToSystemQueue (Message* message)
|
||||
{
|
||||
message->incReferenceCount();
|
||||
getEnv()->CallVoidMethod (android.activity, android.postMessage, (jlong) (pointer_sized_uint) message);
|
||||
return true;
|
||||
}
|
||||
|
||||
JUCE_JNI_CALLBACK (JuceAppActivity, deliverMessage, void, (jobject activity, jlong value))
|
||||
{
|
||||
Message* m = (Message*) (pointer_sized_uint) value;
|
||||
MessageManager::getInstance()->deliverMessage ((Message*) (pointer_sized_uint) value);
|
||||
Message* const message = (Message*) (pointer_sized_uint) value;
|
||||
MessageManager::getInstance()->deliverMessage (message);
|
||||
message->decReferenceCount();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -115,4 +100,31 @@ void MessageManager::broadcastMessage (const String&)
|
|||
{
|
||||
}
|
||||
|
||||
void MessageManager::runDispatchLoop()
|
||||
{
|
||||
}
|
||||
|
||||
class QuitCallback : public CallbackMessage
|
||||
{
|
||||
public:
|
||||
QuitCallback() {}
|
||||
|
||||
void messageCallback()
|
||||
{
|
||||
android.activity.callVoidMethod (android.finish);
|
||||
}
|
||||
};
|
||||
|
||||
void MessageManager::stopDispatchLoop()
|
||||
{
|
||||
(new QuitCallback())->post();
|
||||
quitMessagePosted = true;
|
||||
}
|
||||
|
||||
bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
|
||||
{
|
||||
juce_dispatchNextMessageOnSystemQueue (false);
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -103,6 +103,8 @@ BEGIN_JUCE_NAMESPACE
|
|||
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 (regionClass, "android/graphics/Region") \
|
||||
|
|
@ -116,11 +118,14 @@ BEGIN_JUCE_NAMESPACE
|
|||
#define JUCE_JNI_METHODS(METHOD, STATICMETHOD, FIELD, STATICFIELD) \
|
||||
\
|
||||
STATICMETHOD (activityClass, printToConsole, "printToConsole", "(Ljava/lang/String;)V") \
|
||||
METHOD (activityClass, createNewView, "createNewView", "()Lcom/juce/ComponentPeerView;") \
|
||||
METHOD (activityClass, createNewView, "createNewView", "(Z)Lcom/juce/ComponentPeerView;") \
|
||||
METHOD (activityClass, deleteView, "deleteView", "(Lcom/juce/ComponentPeerView;)V") \
|
||||
METHOD (activityClass, postMessage, "postMessage", "(J)V") \
|
||||
METHOD (activityClass, finish, "finish", "()V") \
|
||||
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 (fileClass, fileExists, "exists", "()Z") \
|
||||
\
|
||||
|
|
@ -137,7 +142,9 @@ BEGIN_JUCE_NAMESPACE
|
|||
METHOD (componentPeerViewClass, isVisible, "isVisible", "()Z") \
|
||||
METHOD (componentPeerViewClass, hasFocus, "hasFocus", "()Z") \
|
||||
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") \
|
||||
|
|
@ -145,6 +152,7 @@ BEGIN_JUCE_NAMESPACE
|
|||
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") \
|
||||
|
|
@ -157,13 +165,13 @@ BEGIN_JUCE_NAMESPACE
|
|||
\
|
||||
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, 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;") \
|
||||
|
|
@ -174,6 +182,13 @@ BEGIN_JUCE_NAMESPACE
|
|||
METHOD (pathClass, quadTo, "quadTo", "(FFFF)V") \
|
||||
METHOD (pathClass, cubicTo, "cubicTo", "(FFFFFF)V") \
|
||||
METHOD (pathClass, closePath, "close", "()V") \
|
||||
\
|
||||
STATICMETHOD (bitmapClass, createBitmap, "createBitmap", "(IILandroid/graphics/Bitmap$Config;)Landroid/graphics/Bitmap;") \
|
||||
STATICFIELD (bitmapConfigClass, ARGB_8888, "ARGB_8888", "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") \
|
||||
|
|
@ -315,7 +330,10 @@ public:
|
|||
inline void clear()
|
||||
{
|
||||
if (obj != 0)
|
||||
{
|
||||
getEnv()->DeleteGlobalRef (obj);
|
||||
obj = 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline GlobalRef& operator= (const GlobalRef& other)
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@
|
|||
// compiled on its own).
|
||||
#if JUCE_INCLUDED_FILE
|
||||
|
||||
static ModifierKeys currentModifiers;
|
||||
|
||||
//==============================================================================
|
||||
class AndroidComponentPeer : public ComponentPeer
|
||||
|
|
@ -36,8 +35,10 @@ public:
|
|||
//==============================================================================
|
||||
AndroidComponentPeer (Component* const component, const int windowStyleFlags)
|
||||
: ComponentPeer (component, windowStyleFlags),
|
||||
view (android.activity.callObjectMethod (android.createNewView))
|
||||
view (android.activity.callObjectMethod (android.createNewView, component->isOpaque()))
|
||||
{
|
||||
if (isFocused())
|
||||
handleFocusGain();
|
||||
}
|
||||
|
||||
~AndroidComponentPeer()
|
||||
|
|
@ -88,7 +89,7 @@ public:
|
|||
|
||||
const Point<int> getScreenPosition() const
|
||||
{
|
||||
JNIEnv* const env = getEnv();
|
||||
/*JNIEnv* const env = getEnv();
|
||||
|
||||
jintArray pos = env->NewIntArray (2);
|
||||
view.callVoidMethod (android.getLocationOnScreen, pos);
|
||||
|
|
@ -97,7 +98,10 @@ public:
|
|||
env->GetIntArrayRegion (pos, 0, 2, coords);
|
||||
env->DeleteLocalRef (pos);
|
||||
|
||||
return Point<int> (coords[0], coords[1]);
|
||||
return Point<int> (coords[0], coords[1]);*/
|
||||
|
||||
return Point<int> (view.callIntMethod (android.getLeft),
|
||||
view.callIntMethod (android.getTop));
|
||||
}
|
||||
|
||||
const Point<int> localToGlobal (const Point<int>& relativePosition)
|
||||
|
|
@ -138,10 +142,9 @@ public:
|
|||
|
||||
bool contains (const Point<int>& position, bool trueIfInAChildWindow) const
|
||||
{
|
||||
// TODO
|
||||
|
||||
return isPositiveAndBelow (position.getX(), component->getWidth())
|
||||
&& isPositiveAndBelow (position.getY(), component->getHeight());
|
||||
&& isPositiveAndBelow (position.getY(), component->getHeight())
|
||||
&& ((! trueIfInAChildWindow) || view.callBooleanMethod (android.containsPoint, position.getX(), position.getY()));
|
||||
}
|
||||
|
||||
const BorderSize<int> getFrameSize() const
|
||||
|
|
@ -162,6 +165,8 @@ public:
|
|||
|
||||
if (makeActive)
|
||||
grabFocus();
|
||||
|
||||
handleBroughtToFront();
|
||||
}
|
||||
|
||||
void toBehind (ComponentPeer* other)
|
||||
|
|
@ -172,21 +177,24 @@ public:
|
|||
//==============================================================================
|
||||
void handleMouseDownCallback (float x, float y, int64 time)
|
||||
{
|
||||
lastMousePos.setXY ((int) x, (int) y);
|
||||
currentModifiers = currentModifiers.withoutMouseButtons();
|
||||
handleMouseEvent (0, Point<int> ((int) x, (int) y), currentModifiers, time);
|
||||
handleMouseEvent (0, lastMousePos, currentModifiers, time);
|
||||
currentModifiers = currentModifiers.withoutMouseButtons().withFlags (ModifierKeys::leftButtonModifier);
|
||||
handleMouseEvent (0, Point<int> ((int) x, (int) y), currentModifiers, time);
|
||||
handleMouseEvent (0, lastMousePos, currentModifiers, time);
|
||||
}
|
||||
|
||||
void handleMouseDragCallback (float x, float y, int64 time)
|
||||
{
|
||||
handleMouseEvent (0, Point<int> ((int) x, (int) y), currentModifiers, time);
|
||||
lastMousePos.setXY ((int) x, (int) y);
|
||||
handleMouseEvent (0, lastMousePos, currentModifiers, time);
|
||||
}
|
||||
|
||||
void handleMouseUpCallback (float x, float y, int64 time)
|
||||
{
|
||||
lastMousePos.setXY ((int) x, (int) y);
|
||||
currentModifiers = currentModifiers.withoutMouseButtons();
|
||||
handleMouseEvent (0, Point<int> ((int) x, (int) y), currentModifiers, time);
|
||||
handleMouseEvent (0, lastMousePos, currentModifiers, time);
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -197,7 +205,15 @@ public:
|
|||
|
||||
void grabFocus()
|
||||
{
|
||||
(void) view.callBooleanMethod (android.requestFocus);
|
||||
view.callBooleanMethod (android.requestFocus);
|
||||
}
|
||||
|
||||
void handleFocusChangeCallback (bool hasFocus)
|
||||
{
|
||||
if (hasFocus)
|
||||
handleFocusGain();
|
||||
else
|
||||
handleFocusLoss();
|
||||
}
|
||||
|
||||
void textInputRequired (const Point<int>& position)
|
||||
|
|
@ -208,8 +224,7 @@ public:
|
|||
//==============================================================================
|
||||
void handlePaintCallback (JNIEnv* env, jobject canvas)
|
||||
{
|
||||
GlobalRef canvasRef (canvas);
|
||||
AndroidLowLevelGraphicsContext g (canvasRef);
|
||||
AndroidLowLevelGraphicsContext g (canvas);
|
||||
handlePaint (g);
|
||||
}
|
||||
|
||||
|
|
@ -243,6 +258,9 @@ public:
|
|||
return 0;
|
||||
}
|
||||
|
||||
static ModifierKeys currentModifiers;
|
||||
static Point<int> lastMousePos;
|
||||
|
||||
private:
|
||||
//==============================================================================
|
||||
GlobalRef view;
|
||||
|
|
@ -250,6 +268,9 @@ private:
|
|||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AndroidComponentPeer);
|
||||
};
|
||||
|
||||
ModifierKeys AndroidComponentPeer::currentModifiers = 0;
|
||||
Point<int> AndroidComponentPeer::lastMousePos;
|
||||
|
||||
//==============================================================================
|
||||
#define JUCE_VIEW_CALLBACK(returnType, javaMethodName, params, juceMethodInvocation) \
|
||||
JUCE_JNI_CALLBACK (ComponentPeerView, javaMethodName, returnType, params) \
|
||||
|
|
@ -269,6 +290,12 @@ JUCE_VIEW_CALLBACK (void, handleMouseDrag, (JNIEnv*, jobject view, jfloat x, jfl
|
|||
JUCE_VIEW_CALLBACK (void, handleMouseUp, (JNIEnv*, jobject view, jfloat x, jfloat y, jlong time),
|
||||
handleMouseUpCallback ((float) x, (float) y, (int64) time))
|
||||
|
||||
JUCE_VIEW_CALLBACK (void, viewSizeChanged, (JNIEnv*, jobject view),
|
||||
handleMovedOrResized())
|
||||
|
||||
JUCE_VIEW_CALLBACK (void, focusChanged, (JNIEnv*, jobject view, jboolean hasFocus),
|
||||
handleFocusChangeCallback (hasFocus))
|
||||
|
||||
//==============================================================================
|
||||
ComponentPeer* Component::createNewPeer (int styleFlags, void*)
|
||||
{
|
||||
|
|
@ -298,8 +325,7 @@ void Desktop::createMouseInputSources()
|
|||
|
||||
const Point<int> MouseInputSource::getCurrentMousePosition()
|
||||
{
|
||||
// TODO
|
||||
return Point<int>();
|
||||
return AndroidComponentPeer::lastMousePos;
|
||||
}
|
||||
|
||||
void Desktop::setMousePosition (const Point<int>& newPosition)
|
||||
|
|
@ -316,12 +342,12 @@ bool KeyPress::isKeyCurrentlyDown (const int keyCode)
|
|||
|
||||
void ModifierKeys::updateCurrentModifiers() throw()
|
||||
{
|
||||
// not needed
|
||||
currentModifiers = AndroidComponentPeer::currentModifiers;
|
||||
}
|
||||
|
||||
const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
|
||||
{
|
||||
return currentModifiers;
|
||||
return AndroidComponentPeer::currentModifiers;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -340,11 +366,6 @@ bool AlertWindow::showNativeDialogBox (const String& title,
|
|||
}
|
||||
|
||||
//==============================================================================
|
||||
Image::SharedImage* Image::SharedImage::createNativeImage (PixelFormat format, int width, int height, bool clearImage)
|
||||
{
|
||||
return createSoftwareImage (format, width, height, clearImage);
|
||||
}
|
||||
|
||||
void Desktop::setScreenSaverEnabled (const bool isEnabled)
|
||||
{
|
||||
// TODO
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue