1a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford/* 2a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * Copyright (C) 2012 The Android Open Source Project 3a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * 4a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * Licensed under the Apache License, Version 2.0 (the "License"); 5a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * you may not use this file except in compliance with the License. 6a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * You may obtain a copy of the License at 7a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * 8a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * http://www.apache.org/licenses/LICENSE-2.0 9a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * 10a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * Unless required by applicable law or agreed to in writing, software 11a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * distributed under the License is distributed on an "AS IS" BASIS, 12a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * See the License for the specific language governing permissions and 14a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford * limitations under the License. 15a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford */ 16a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 17a93d5ee9c409e2328dcbe2326591436f8ac23146John Hofordpackage com.android.gallery3d.filtershow.imageshow; 18a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 19a93d5ee9c409e2328dcbe2326591436f8ac23146John Hofordimport android.content.Context; 20a93d5ee9c409e2328dcbe2326591436f8ac23146John Hofordimport android.graphics.Canvas; 21a93d5ee9c409e2328dcbe2326591436f8ac23146John Hofordimport android.graphics.Color; 22a93d5ee9c409e2328dcbe2326591436f8ac23146John Hofordimport android.graphics.Matrix; 23a93d5ee9c409e2328dcbe2326591436f8ac23146John Hofordimport android.graphics.Paint; 24a93d5ee9c409e2328dcbe2326591436f8ac23146John Hofordimport android.graphics.RadialGradient; 253e3e9e219a76e8ef4fb56b8ef4c6e0bac06c6cd1John Hofordimport android.graphics.Rect; 26a93d5ee9c409e2328dcbe2326591436f8ac23146John Hofordimport android.graphics.RectF; 27a93d5ee9c409e2328dcbe2326591436f8ac23146John Hofordimport android.graphics.Shader; 2837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hofordimport android.util.Log; 29a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 30a93d5ee9c409e2328dcbe2326591436f8ac23146John Hofordimport com.android.gallery3d.R; 31a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 32a93d5ee9c409e2328dcbe2326591436f8ac23146John Hofordpublic class EclipseControl { 33a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford private float mCenterX = Float.NaN; 34a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford private float mCenterY = 0; 35a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford private float mRadiusX = 200; 36a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford private float mRadiusY = 300; 37a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford private static int MIN_TOUCH_DIST = 80;// should be a resource & in dips 3837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford private static String LOGTAG = "EclipseControl"; 39a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford private float[] handlex = new float[9]; 40a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford private float[] handley = new float[9]; 41a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford private int mSliderColor; 42a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford private int mCenterDotSize = 40; 43a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford private float mDownX; 44a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford private float mDownY; 45a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford private float mDownCenterX; 46a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford private float mDownCenterY; 47a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford private float mDownRadiusX; 48a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford private float mDownRadiusY; 49a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford private Matrix mScrToImg; 50a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 5133de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford private boolean mShowReshapeHandles = true; 52d4653680279a85720f792f21e32578ccf5c6c34fJohn Hoford public final static int HAN_CENTER = 0; 53d4653680279a85720f792f21e32578ccf5c6c34fJohn Hoford public final static int HAN_NORTH = 7; 54d4653680279a85720f792f21e32578ccf5c6c34fJohn Hoford public final static int HAN_NE = 8; 55d4653680279a85720f792f21e32578ccf5c6c34fJohn Hoford public final static int HAN_EAST = 1; 56d4653680279a85720f792f21e32578ccf5c6c34fJohn Hoford public final static int HAN_SE = 2; 57d4653680279a85720f792f21e32578ccf5c6c34fJohn Hoford public final static int HAN_SOUTH = 3; 58d4653680279a85720f792f21e32578ccf5c6c34fJohn Hoford public final static int HAN_SW = 4; 59d4653680279a85720f792f21e32578ccf5c6c34fJohn Hoford public final static int HAN_WEST = 5; 60d4653680279a85720f792f21e32578ccf5c6c34fJohn Hoford public final static int HAN_NW = 6; 613e3e9e219a76e8ef4fb56b8ef4c6e0bac06c6cd1John Hoford private Rect mImageBounds; 62a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 63a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford public EclipseControl(Context context) { 6433de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford mSliderColor = Color.WHITE; 65a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 66a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 67a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford public void setRadius(float x, float y) { 68a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford mRadiusX = x; 69a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford mRadiusY = y; 70a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 71a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 72a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford public void setCenter(float x, float y) { 73a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford mCenterX = x; 74a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford mCenterY = y; 75a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 76a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 77a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford public int getCloseHandle(float x, float y) { 78a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float min = Float.MAX_VALUE; 79a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford int handle = -1; 80a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford for (int i = 0; i < handlex.length; i++) { 81a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float dx = handlex[i] - x; 82a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float dy = handley[i] - y; 83a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float dist = dx * dx + dy * dy; 84a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford if (dist < min) { 85a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford min = dist; 86a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford handle = i; 87a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 88a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 89a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 90a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford if (min < MIN_TOUCH_DIST * MIN_TOUCH_DIST) { 91a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford return handle; 92a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 93a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford for (int i = 0; i < handlex.length; i++) { 94a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float dx = handlex[i] - x; 95a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float dy = handley[i] - y; 96a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float dist = (float) Math.sqrt(dx * dx + dy * dy); 97a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 98a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 99a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford return -1; 100a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 101a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 1023e3e9e219a76e8ef4fb56b8ef4c6e0bac06c6cd1John Hoford public void setScrImageInfo(Matrix scrToImg, Rect imageBounds) { 103a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford mScrToImg = scrToImg; 1043e3e9e219a76e8ef4fb56b8ef4c6e0bac06c6cd1John Hoford mImageBounds = new Rect(imageBounds); 1053e3e9e219a76e8ef4fb56b8ef4c6e0bac06c6cd1John Hoford } 1063e3e9e219a76e8ef4fb56b8ef4c6e0bac06c6cd1John Hoford 1073e3e9e219a76e8ef4fb56b8ef4c6e0bac06c6cd1John Hoford private boolean centerIsOutside(float x1, float y1) { 10837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford return (!mImageBounds.contains((int) x1, (int) y1)); 109a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 110a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 111708753f5a087eb759ef48fe9b41ef2274d2e88a7John Hoford public void actionDown(float x, float y, Oval oval) { 11237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford float[] point = new float[]{ 11337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford x, y}; 114a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford mScrToImg.mapPoints(point); 115a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford mDownX = point[0]; 116a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford mDownY = point[1]; 117708753f5a087eb759ef48fe9b41ef2274d2e88a7John Hoford mDownCenterX = oval.getCenterX(); 118708753f5a087eb759ef48fe9b41ef2274d2e88a7John Hoford mDownCenterY = oval.getCenterY(); 119708753f5a087eb759ef48fe9b41ef2274d2e88a7John Hoford mDownRadiusX = oval.getRadiusX(); 120708753f5a087eb759ef48fe9b41ef2274d2e88a7John Hoford mDownRadiusY = oval.getRadiusY(); 12137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford } 12237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford 123a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 124a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford public void actionMove(int handle, float x, float y, Oval oval) { 12537f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford float[] point = new float[]{ 12637f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford x, y}; 127a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford mScrToImg.mapPoints(point); 128a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford x = point[0]; 129a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford y = point[1]; 130708753f5a087eb759ef48fe9b41ef2274d2e88a7John Hoford 13152fab9f1595cfcabe85d81325bdb9b486bc8c306John Hoford // Test if the matrix is swapping x and y 13252fab9f1595cfcabe85d81325bdb9b486bc8c306John Hoford point[0] = 0; 13352fab9f1595cfcabe85d81325bdb9b486bc8c306John Hoford point[1] = 1; 13452fab9f1595cfcabe85d81325bdb9b486bc8c306John Hoford mScrToImg.mapVectors(point); 13552fab9f1595cfcabe85d81325bdb9b486bc8c306John Hoford boolean swapxy = (point[0] > 0.0f); 13652fab9f1595cfcabe85d81325bdb9b486bc8c306John Hoford 137a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford int sign = 1; 138a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford switch (handle) { 139a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford case HAN_CENTER: 140a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float ctrdx = mDownX - mDownCenterX; 141a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float ctrdy = mDownY - mDownCenterY; 1423e3e9e219a76e8ef4fb56b8ef4c6e0bac06c6cd1John Hoford if (centerIsOutside(x - ctrdx, y - ctrdy)) { 1433e3e9e219a76e8ef4fb56b8ef4c6e0bac06c6cd1John Hoford break; 1443e3e9e219a76e8ef4fb56b8ef4c6e0bac06c6cd1John Hoford } 145708753f5a087eb759ef48fe9b41ef2274d2e88a7John Hoford oval.setCenter((x - ctrdx), (y - ctrdy)); 146a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford // setRepresentation(mVignetteRep); 147a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford break; 148a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford case HAN_NORTH: 149a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford sign = -1; 150a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford case HAN_SOUTH: 15152fab9f1595cfcabe85d81325bdb9b486bc8c306John Hoford if (swapxy) { 15252fab9f1595cfcabe85d81325bdb9b486bc8c306John Hoford float raddx = mDownRadiusY - Math.abs(mDownX - mDownCenterY); 153708753f5a087eb759ef48fe9b41ef2274d2e88a7John Hoford oval.setRadiusY(Math.abs(x - oval.getCenterY() + sign * raddx)); 15452fab9f1595cfcabe85d81325bdb9b486bc8c306John Hoford } else { 15552fab9f1595cfcabe85d81325bdb9b486bc8c306John Hoford float raddy = mDownRadiusY - Math.abs(mDownY - mDownCenterY); 156708753f5a087eb759ef48fe9b41ef2274d2e88a7John Hoford oval.setRadiusY(Math.abs(y - oval.getCenterY() + sign * raddy)); 15752fab9f1595cfcabe85d81325bdb9b486bc8c306John Hoford } 158a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford break; 159a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford case HAN_EAST: 160a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford sign = -1; 161a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford case HAN_WEST: 16252fab9f1595cfcabe85d81325bdb9b486bc8c306John Hoford if (swapxy) { 16352fab9f1595cfcabe85d81325bdb9b486bc8c306John Hoford float raddy = mDownRadiusX - Math.abs(mDownY - mDownCenterX); 164708753f5a087eb759ef48fe9b41ef2274d2e88a7John Hoford oval.setRadiusX(Math.abs(y - oval.getCenterX() + sign * raddy)); 16552fab9f1595cfcabe85d81325bdb9b486bc8c306John Hoford } else { 16652fab9f1595cfcabe85d81325bdb9b486bc8c306John Hoford float raddx = mDownRadiusX - Math.abs(mDownX - mDownCenterX); 167708753f5a087eb759ef48fe9b41ef2274d2e88a7John Hoford oval.setRadiusX(Math.abs(x - oval.getCenterX() - sign * raddx)); 16852fab9f1595cfcabe85d81325bdb9b486bc8c306John Hoford } 169a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford break; 170a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford case HAN_SE: 171a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford case HAN_NE: 172a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford case HAN_SW: 173a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford case HAN_NW: 174a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float sin45 = (float) Math.sin(45); 175a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float dr = (mDownRadiusX + mDownRadiusY) * sin45; 176a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float ctr_dx = mDownX - mDownCenterX; 177a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float ctr_dy = mDownY - mDownCenterY; 178a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float downRad = Math.abs(ctr_dx) + Math.abs(ctr_dy) - dr; 179708753f5a087eb759ef48fe9b41ef2274d2e88a7John Hoford float rx = oval.getRadiusX(); 180708753f5a087eb759ef48fe9b41ef2274d2e88a7John Hoford float ry = oval.getRadiusY(); 181a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float r = (Math.abs(rx) + Math.abs(ry)) * sin45; 182708753f5a087eb759ef48fe9b41ef2274d2e88a7John Hoford float dx = x - oval.getCenterX(); 183708753f5a087eb759ef48fe9b41ef2274d2e88a7John Hoford float dy = y - oval.getCenterY(); 184a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float nr = Math.abs(Math.abs(dx) + Math.abs(dy) - downRad); 185708753f5a087eb759ef48fe9b41ef2274d2e88a7John Hoford oval.setRadius((rx * nr / r), (ry * nr / r)); 186a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 187a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford break; 188a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 189a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 190a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 1910a898008099c6747a1393f81c1b4de92e3bc04ebJohn Hoford public void paintGrayPoint(Canvas canvas, float x, float y) { 19280678e64b3a61bdf5f7fe57c486d12a5309f4a20Andreas Gampe if (Float.isNaN(x)) { 1930a898008099c6747a1393f81c1b4de92e3bc04ebJohn Hoford return; 1940a898008099c6747a1393f81c1b4de92e3bc04ebJohn Hoford } 1950a898008099c6747a1393f81c1b4de92e3bc04ebJohn Hoford 1960a898008099c6747a1393f81c1b4de92e3bc04ebJohn Hoford Paint paint = new Paint(); 1970a898008099c6747a1393f81c1b4de92e3bc04ebJohn Hoford 1980a898008099c6747a1393f81c1b4de92e3bc04ebJohn Hoford paint.setStyle(Paint.Style.FILL); 1990a898008099c6747a1393f81c1b4de92e3bc04ebJohn Hoford paint.setColor(Color.BLUE); 20037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford int[] colors3 = new int[]{ 20137f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford Color.GRAY, Color.LTGRAY, 0x66000000, 0}; 20237f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford RadialGradient g = new RadialGradient(x, y, mCenterDotSize, colors3, new float[]{ 20337f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford 0, .3f, .31f, 1}, Shader.TileMode.CLAMP); 2040a898008099c6747a1393f81c1b4de92e3bc04ebJohn Hoford paint.setShader(g); 2050a898008099c6747a1393f81c1b4de92e3bc04ebJohn Hoford canvas.drawCircle(x, y, mCenterDotSize, paint); 2060a898008099c6747a1393f81c1b4de92e3bc04ebJohn Hoford } 2070a898008099c6747a1393f81c1b4de92e3bc04ebJohn Hoford 2080a898008099c6747a1393f81c1b4de92e3bc04ebJohn Hoford public void paintPoint(Canvas canvas, float x, float y) { 20980678e64b3a61bdf5f7fe57c486d12a5309f4a20Andreas Gampe if (Float.isNaN(x)) { 210a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford return; 211a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 212a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 213a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford Paint paint = new Paint(); 214a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 215a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford paint.setStyle(Paint.Style.FILL); 216a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford paint.setColor(Color.BLUE); 21737f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford int[] colors3 = new int[]{ 21837f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford mSliderColor, mSliderColor, 0x66000000, 0}; 21937f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford RadialGradient g = new RadialGradient(x, y, mCenterDotSize, colors3, new float[]{ 22037f8e432f4eb94d0ab483bfdc2a1fa024508e85fJohn Hoford 0, .3f, .31f, 1}, Shader.TileMode.CLAMP); 221a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford paint.setShader(g); 222a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford canvas.drawCircle(x, y, mCenterDotSize, paint); 223a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 224a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 225a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford void paintRadius(Canvas canvas, float cx, float cy, float rx, float ry) { 22680678e64b3a61bdf5f7fe57c486d12a5309f4a20Andreas Gampe if (Float.isNaN(cx)) { 227a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford return; 228a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 229a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford int mSliderColor = 0xFF33B5E5; 230a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford Paint paint = new Paint(); 231a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford RectF rect = new RectF(cx - rx, cy - ry, cx + rx, cy + ry); 232a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford paint.setAntiAlias(true); 233a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford paint.setStyle(Paint.Style.STROKE); 234a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford paint.setStrokeWidth(6); 235a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford paint.setColor(Color.BLACK); 236a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford paintOvallines(canvas, rect, paint, cx, cy, rx, ry); 237a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 238a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford paint.setStrokeWidth(3); 239a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford paint.setColor(Color.WHITE); 240a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford paintOvallines(canvas, rect, paint, cx, cy, rx, ry); 241a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 242a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 243a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford public void paintOvallines( 244a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford Canvas canvas, RectF rect, Paint paint, float cx, float cy, float rx, float ry) { 245a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford canvas.drawOval(rect, paint); 246a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float da = 4; 247a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float arclen = da + da; 24833de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford if (mShowReshapeHandles) { 24933de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford paint.setStyle(Paint.Style.STROKE); 25033de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford 25133de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford for (int i = 0; i < 361; i += 90) { 25233de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford float dx = rx + 10; 25333de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford float dy = ry + 10; 25433de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford rect.left = cx - dx; 25533de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford rect.top = cy - dy; 25633de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford rect.right = cx + dx; 25733de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford rect.bottom = cy + dy; 25833de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford canvas.drawArc(rect, i - da, arclen, false, paint); 25933de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford dx = rx - 10; 26033de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford dy = ry - 10; 26133de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford rect.left = cx - dx; 26233de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford rect.top = cy - dy; 26333de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford rect.right = cx + dx; 26433de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford rect.bottom = cy + dy; 26533de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford canvas.drawArc(rect, i - da, arclen, false, paint); 26633de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford } 267a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 268a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford da *= 2; 26933de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford paint.setStyle(Paint.Style.FILL); 27033de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford 271a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford for (int i = 45; i < 361; i += 90) { 272a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford double angle = Math.PI * i / 180.; 273a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float x = cx + (float) (rx * Math.cos(angle)); 274a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float y = cy + (float) (ry * Math.sin(angle)); 275a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford canvas.drawRect(x - da, y - da, x + da, y + da, paint); 276a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 27733de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford paint.setStyle(Paint.Style.STROKE); 278a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford rect.left = cx - rx; 279a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford rect.top = cy - ry; 280a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford rect.right = cx + rx; 281a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford rect.bottom = cy + ry; 282a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 283a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 284a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford public void fillHandles(Canvas canvas, float cx, float cy, float rx, float ry) { 285a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford handlex[0] = cx; 286a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford handley[0] = cy; 287a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford int k = 1; 288a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 289a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford for (int i = 0; i < 360; i += 45) { 290a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford double angle = Math.PI * i / 180.; 291a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 292a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float x = cx + (float) (rx * Math.cos(angle)); 293a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford float y = cy + (float) (ry * Math.sin(angle)); 294a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford handlex[k] = x; 295a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford handley[k] = y; 296a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 297a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford k++; 298a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 299a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 300a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford 301a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford public void draw(Canvas canvas) { 302a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford paintRadius(canvas, mCenterX, mCenterY, mRadiusX, mRadiusY); 303a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford fillHandles(canvas, mCenterX, mCenterY, mRadiusX, mRadiusY); 304a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford paintPoint(canvas, mCenterX, mCenterY); 305a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford } 3061863a3119a802517b1c2a53763f904f73fdc940bJohn Hoford 3071863a3119a802517b1c2a53763f904f73fdc940bJohn Hoford public boolean isUndefined() { 3081863a3119a802517b1c2a53763f904f73fdc940bJohn Hoford return Float.isNaN(mCenterX); 3091863a3119a802517b1c2a53763f904f73fdc940bJohn Hoford } 31033de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford 31133de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford public void setShowReshapeHandles(boolean showReshapeHandles) { 31233de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford this.mShowReshapeHandles = showReshapeHandles; 31333de212ec780eaf2bc8d86908f07da33ea8dd7f2John Hoford } 314a93d5ee9c409e2328dcbe2326591436f8ac23146John Hoford} 315