It works!!

This commit is contained in:
dgis 2018-12-03 22:40:52 +00:00
parent 327e3ca0bc
commit 1d997e6036
2 changed files with 29 additions and 77 deletions

View file

@ -21,6 +21,22 @@ const TCHAR * assetsPrefix = _T("assets/"),
assetsPrefixLength = 7;
AAssetManager * assetManager;
static HDC mainPaintDC = NULL;
struct timerEvent {
BOOL valid;
int timerId;
LPTIMECALLBACK fptc;
DWORD_PTR dwUser;
timer_t timer;
};
#define MAX_TIMER 10
struct timerEvent timerEvents[MAX_TIMER];
void win32Init() {
for (int i = 0; i < MAX_TIMER; ++i) {
timerEvents[i].valid = FALSE;
}
}
VOID OutputDebugString(LPCSTR lpOutputString) {
LOGD("%s", lpOutputString);
@ -799,8 +815,10 @@ BOOL StretchBlt(HDC hdcDest, int xDest, int yDest, int wDest, int hDest, HDC hdc
int destinationHeight = androidBitmapInfo.height;
//https://softwareengineering.stackexchange.com/questions/148123/what-is-the-algorithm-to-copy-a-region-of-one-bitmap-into-a-region-in-another
float src_dx = wDest / wSrc;
float src_dy = hDest / hSrc;
// float src_dx = wDest / wSrc;
// float src_dy = hDest / hSrc;
float src_dx = (float)wSrc / (float)wDest;
float src_dy = (float)hSrc / (float)hDest;
float src_maxx = xSrc + wSrc;
float src_maxy = ySrc + hSrc;
float dst_maxx = xDest + wDest;
@ -824,7 +842,7 @@ BOOL StretchBlt(HDC hdcDest, int xDest, int yDest, int wDest, int hDest, HDC hdc
//dst.bmp[x,y] = src.bmp[src_curx, src_cury];
BYTE * destinationPixel = pixelsDestination + (int)(4.0 * x + destinationStride * y);
BYTE * sourcePixel = pixelsSource + (int)(sourceBytes * src_curx + sourceStride * src_cury);
BYTE * sourcePixel = pixelsSource + (int)(sourceBytes * (int)src_curx) + (int)(sourceStride * (int)src_cury);
// -> ARGB_8888
switch (sourceBytes) {
@ -999,23 +1017,6 @@ HANDLE WINAPI GetClipboardData(UINT uFormat) {
return NULL;
}
struct timerEvent {
BOOL valid;
int timerId;
LPTIMECALLBACK fptc;
DWORD_PTR dwUser;
timer_t timer;
};
#define MAX_TIMER 10
struct timerEvent timerEvents[MAX_TIMER];
void win32Init() {
for (int i = 0; i < MAX_TIMER; ++i) {
timerEvents[i].valid = FALSE;
}
}
void timerCallback(int timerId) {
if(timerId >= 0 && timerId < MAX_TIMER && timerEvents[timerId].valid) {
timerEvents[timerId].fptc(timerId + 1, 0, timerEvents[timerId].dwUser, 0, 0);

View file

@ -8,6 +8,7 @@ import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.support.v4.view.ViewCompat;
import android.util.DisplayMetrics;
import android.util.Log;
@ -28,6 +29,7 @@ public class MainScreenView extends SurfaceView {
protected static final String TAG = "MainScreenView";
private Bitmap bitmapMainScreen;
private HashMap<Integer, Integer> vkmap;
private float screenScale = 3.0f;
public MainScreenView(Context context) {
super(context);
@ -40,60 +42,6 @@ public class MainScreenView extends SurfaceView {
bitmapMainScreen.eraseColor(Color.LTGRAY);
NativeLib.start(mgr, bitmapMainScreen, this);
commonInitialize(context);
}
/**
* Common initialize method.
* @param context The activity context.
*/
private void commonInitialize(Context context) {
//this.mContext = context;
// // Prevent the out of memory in OpenGL with Tegra 2 devices
// //if(!Utils.hasHighMemory(context))
// setLayerType(View.LAYER_TYPE_SOFTWARE, null);
// //mAntiAliased = Utils.hasHighMemory(context);
// mScreenDensity = getResources().getDisplayMetrics().density;
//
// mVectorsCanvasRenderer = new VectorsCanvasRenderer();
// mVectorsCanvasRenderer.setStrokeColor(0xff000000); // Black
// Paint paint = mVectorsCanvasRenderer.getPaint();
// paint.setColor(Color.BLACK);
// paint.setStyle(Paint.Style.STROKE);
// paint.setStrokeWidth(1.0f * mScreenDensity);
// paint.setAntiAlias(mAntiAliased);
// mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
//
// @Override
// public boolean onDoubleTap(MotionEvent e) {
// float scaleFactorPrevious = currentProject.viewScaleFactor;
// currentProject.viewScaleFactor *= 2f;
// if(currentProject.viewScaleFactor > mScaleFactorMax)
// currentProject.viewScaleFactor = mScaleFactorMin;
// else {
// constrainScale();
// scaleWithFocus(e.getX(), e.getY(), scaleFactorPrevious);
// }
// constrainPan();
// invalidate();
// return true;
// }
//
// @Override
// public boolean onDown(MotionEvent e) {
// //Log.d(TAG, "GestureDetector.onDown()");
// if(!mOverScroller.isFinished()) {
// mOverScroller.forceFinished(true);
// //ViewCompat.postInvalidateOnAnimation(CanvasView.this);
// //invalidate();
// }
// return true;
// }
//
// });
vkmap = new HashMap<Integer, Integer>();
vkmap.put(KeyEvent.KEYCODE_BACK, 0x08); // VK_BACK
vkmap.put(KeyEvent.KEYCODE_TAB, 0x09); // VK_TAB
@ -188,7 +136,6 @@ public class MainScreenView extends SurfaceView {
setWillNotDraw(false);
}
@SuppressLint("ClickableViewAccessibility")
public boolean onTouchEvent(MotionEvent event) {
// Let the ScaleGestureDetector inspect all events.
@ -202,12 +149,12 @@ public class MainScreenView extends SurfaceView {
switch (action) {
case MotionEvent.ACTION_DOWN:
//Log.d(TAG, "ACTION_DOWN count: " + touchCount + ", PanPrevious: " + mPanPrevious.toString());
NativeLib.buttonDown((int)event.getX(0), (int)event.getY(0));
NativeLib.buttonDown((int)(event.getX(0) / screenScale), (int)(event.getY(0) / screenScale));
break;
// case MotionEvent.ACTION_MOVE:
// break;
case MotionEvent.ACTION_UP:
NativeLib.buttonUp((int)event.getX(0), (int)event.getY(0));
NativeLib.buttonUp((int)(event.getX(0) / screenScale), (int)(event.getY(0) / screenScale));
break;
// case MotionEvent.ACTION_CANCEL:
// break;
@ -270,7 +217,11 @@ public class MainScreenView extends SurfaceView {
protected void onDraw(Canvas canvas) {
//Log.d(TAG, "onDraw() mIsScaling: " + mIsScaling + ", mIsPanning: " + mIsPanning + ", mIsFlinging: " + mIsFlinging);
//NativeLib.draw();
canvas.save();
//canvas.translate(mViewPanOffsetX, mViewPanOffsetY);
canvas.scale(screenScale, screenScale);
canvas.drawBitmap(bitmapMainScreen, 0, 0, null);
canvas.restore();
}
void updateCallback() {