App
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
mhr.appandroid.views.CurvesView Class Reference
Inheritance diagram for mhr.appandroid.views.CurvesView:

Classes

interface  CurvesViewChangeListener
 
class  GestureListener
 

Public Member Functions

 CurvesView (Context context)
 
 CurvesView (Context context, AttributeSet attrs)
 
 CurvesView (Context context, AttributeSet attrs, int defStyle)
 
void setCurvesChangeListener (CurvesViewChangeListener l)
 
float[][] getPoints ()
 
void setPoints (float[][] pts)
 
void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
 
boolean onTouchEvent (MotionEvent ev)
 

Protected Member Functions

boolean removeSelPoint ()
 
int addPoint (float xx, float yy)
 
void init ()
 
int xToGlob (float xVal)
 
int yToGlob (float yVal)
 
float xToNorm (float xVal)
 
float yToNorm (float yVal)
 
void prepareCurve ()
 
void y2ValsInit ()
 
void cpInit ()
 
void onSizeChanged (int w, int h, int oldw, int oldh)
 Voláno v okamžiku, kdy view dostane rozměry.
 
void onDraw (Canvas canvas)
 

Protected Attributes

GestureDetector detector
 
Bitmap cPressed
 
Bitmap cNormal
 
Rect boundingRect
 
Rect curvesRect
 
Rect cRect
 
int xLength
 
int yLength
 
float[] x
 
float[] xc1
 
float[] xc2
 
float[] y
 
float[] y2
 
float[] yc1
 
float[] yc2
 
int cWidth
 
int cHeight
 
int cXCenter
 
int cYCenter
 
int xOffset
 
int yOffset
 
int selIndex = -1
 
Paint frame
 
RectF marginRect
 
Paint marginRectPaint
 
CurvesViewChangeListener listener = null
 
ShapeDrawable curve
 
float minDelta = 0.001f
 

Detailed Description

Definition at line 23 of file CurvesView.java.

Constructor & Destructor Documentation

mhr.appandroid.views.CurvesView.CurvesView ( Context  context)
inline

Definition at line 287 of file CurvesView.java.

{
super(context);
init();
}
mhr.appandroid.views.CurvesView.CurvesView ( Context  context,
AttributeSet  attrs 
)
inline

Definition at line 292 of file CurvesView.java.

{
super(context, attrs);
init();
}
mhr.appandroid.views.CurvesView.CurvesView ( Context  context,
AttributeSet  attrs,
int  defStyle 
)
inline

Definition at line 297 of file CurvesView.java.

{
super(context, attrs, defStyle);
init();
}

Member Function Documentation

int mhr.appandroid.views.CurvesView.addPoint ( float  xx,
float  yy 
)
inlineprotected

Definition at line 143 of file CurvesView.java.

{
int pos = -1;
if (xx < 0 || xx > 1 || yy < 0 || yy > 1) {
return pos;
}
for (int i = 1; i < x.length; i++) { // Nula nema cenu, mensi by znamenalo BUG
if (x[i] > xx) {
pos = i;
break;
}
}
if (pos < 0) {
return pos;
}
xx = (xx - x[pos - 1]) < minDelta ? x[pos - 1] + minDelta : (x[pos] - xx) < minDelta ? x[pos] - minDelta : xx; // Korekce pokud nahodou koliduje
if (((x[pos] - xx) >= minDelta) && ((xx - x[pos - 1]) >= minDelta)) { // Na novy bod je misto..
int ptsCount = x.length;
float[] tx = new float[ptsCount + 1];
float[] ty = new float[ptsCount + 1];
int i = 0;
while (i < pos) {
tx[i] = x[i];
ty[i] = y[i];
i++;
}
tx[i] = xx;
ty[i] = yy;
while (i < x.length) {
tx[i+1] = x[i];
ty[i+1] = y[i];
i++;
}
x = tx;
y = ty;
y2 = new float[ptsCount + 1];
xc1 = new float[ptsCount];
xc2 = new float[ptsCount];
yc1 = new float[ptsCount];
yc2 = new float[ptsCount];
}
return pos;
}
void mhr.appandroid.views.CurvesView.cpInit ( )
inlineprotected

Inicializuje hodnoty kontrolních bodů tak, aby Bezierovy kubické křivky přibližně odpovídaly kubickému splajnu. interval mezi interpolovanymi body ve směru x je rozdělen na třetiny, a tam jsou umístěny kontrolní body - posun ve směru y je dán velikostí derivace, která je určena ze vztahu pro kubický spline, kterým by se proložily dané body.

Definition at line 365 of file CurvesView.java.

{
int n = x.length - 1;
double d0;
double d1;
double delta;
for (int i = 0; i < n; i++) {
d0 = (y[i+1] - y[i]) / (x[i+1] - x[i]) - 2.0/6.0 * (x[i+1] - x[i]) * y2[i] - 1.0/6.0 * (x[i+1] - x[i]) * y2[i+1];
d1 = (y[i+1] - y[i]) / (x[i+1] - x[i]) + 1.0/6.0 * (x[i+1] - x[i]) * y2[i] + 2.0/6.0 * (x[i+1] - x[i]) * y2[i+1];
delta = x[i + 1] - x[i];
yc1[i] = (float) (y[i] + d0 * (delta) / 3.0);
yc2[i] = (float) (y[i+1] - d1 * (delta) / 3.0);
xc1[i] = (float) (x[i] + delta / 3.0);
xc2[i] = (float) (x[i+1] - delta / 3.0);
}
}
float [][] mhr.appandroid.views.CurvesView.getPoints ( )
inline

Definition at line 395 of file CurvesView.java.

{
float[][] retVal = new float[2][x.length];
for (int i = 0; i < x.length; i++) {
retVal[0][i] = x[i];
retVal[1][i] = 1.0f - y[i];
}
return retVal;
}
void mhr.appandroid.views.CurvesView.init ( )
inlineprotected

Definition at line 244 of file CurvesView.java.

{
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
cPressed = BitmapFactory.decodeResource(getResources(), R.drawable.scrubber_control_pressed_bw);
cNormal = BitmapFactory.decodeResource(getResources(), R.drawable.scrubber_control_normal_bw);
detector = new GestureDetector(getContext(), new GestureListener());
int ptsCount = 2;
x = new float[] {0.0f, 1.0f};
y = new float[] {1.0f, 0.0f};
y2 = new float[ptsCount];
xc1 = new float[ptsCount - 1];
xc2 = new float[ptsCount - 1];
yc1 = new float[ptsCount - 1];
yc2 = new float[ptsCount - 1];
cWidth = cNormal.getWidth();
cHeight = cNormal.getHeight();
cRect = new Rect(0, 0, cWidth, cHeight);
frame = new Paint();
frame.setColor(0xFFFFFFFF);
frame.setStyle(Style.STROKE);
frame.setStrokeWidth(2);
frame.setAntiAlias(true);
marginRectPaint = new Paint();
marginRectPaint.setColor(0xFF000000);
marginRectPaint.setStyle(Style.STROKE);
}
void mhr.appandroid.views.CurvesView.onDraw ( Canvas  canvas)
inlineprotected

Definition at line 461 of file CurvesView.java.

{
canvas.drawRect(curvesRect, frame);
Paint paint = curve.getPaint();
paint.setStrokeWidth(2.0f / xLength);
curve.setBounds(curvesRect);
curve.draw(canvas);
canvas.drawRect(marginRect, marginRectPaint);
for (int i = 0; i < x.length; i++) {
if (i == selIndex) {
canvas.drawBitmap(cPressed, x[i] * xLength + xOffset - cXCenter, y[i] * yLength + yOffset - cYCenter, null);
} else {
canvas.drawBitmap(cNormal, x[i] * xLength + xOffset - cXCenter, y[i] * yLength + yOffset - cYCenter, null);
}
}
}
void mhr.appandroid.views.CurvesView.onMeasure ( int  widthMeasureSpec,
int  heightMeasureSpec 
)
inline

Definition at line 429 of file CurvesView.java.

{
int width = MeasureSpec.getSize(widthMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
// Abychom získaly největší možný čtverec, je nutné nastavit řídící rozměr a ten co se má přizpůsobit na 0. Obrácený postup s hledáním minima nefunguje...
if (width < height) {
width = height;
} else {
height = width;
}
setMeasuredDimension(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY));
}
void mhr.appandroid.views.CurvesView.onSizeChanged ( int  w,
int  h,
int  oldw,
int  oldh 
)
inlineprotected

Voláno v okamžiku, kdy view dostane rozměry.

Definition at line 443 of file CurvesView.java.

{
super.onSizeChanged(w, h, oldw, oldh);
xLength = w - 2 * xOffset;
yLength = h - 2 * yOffset;
boundingRect = new Rect(0, 0, w, h);
curvesRect = new Rect(xOffset, yOffset, w - xOffset, h - yOffset);
marginRect = new RectF(
xOffset / 2.0f,
yOffset / 2.0f,
w - xOffset / 2.0f,
h - yOffset / 2.0f);
marginRectPaint.setStrokeWidth(xOffset);
}
boolean mhr.appandroid.views.CurvesView.onTouchEvent ( MotionEvent  ev)
inline

Definition at line 478 of file CurvesView.java.

{
detector.onTouchEvent(ev);
ViewParent parent = getParent();
if (parent != null) {
parent.requestDisallowInterceptTouchEvent(true);
}
if (ev.getAction() == MotionEvent.ACTION_UP) {
selIndex = -1;
invalidate();
if (listener != null) {
}
}
return true;
}
void mhr.appandroid.views.CurvesView.prepareCurve ( )
inlineprotected

Definition at line 320 of file CurvesView.java.

{
cpInit();
Path p = new Path();
for (int i = 0; i < x.length - 1; i++) {
p.moveTo(x[i], y[i]);
p.cubicTo(xc1[i], yc1[i], xc2[i], yc2[i], x[i+1], y[i+1]);
}
curve = new ShapeDrawable(new PathShape(p, 1, 1));
Paint paint = curve.getPaint();
paint.setStyle(Style.STROKE);
paint.setColor(0xFFFFFFFF);
paint.setAntiAlias(true);
}
boolean mhr.appandroid.views.CurvesView.removeSelPoint ( )
inlineprotected

Definition at line 111 of file CurvesView.java.

{
if (selIndex < 1 || selIndex > x.length - 2) {
selIndex = -1;
return false;
}
int ptsCount = x.length;
float[] tx = new float[ptsCount - 1];
float[] ty = new float[ptsCount - 1];
int i = 0;
while (i < selIndex) {
tx[i] = x[i];
ty[i] = y[i];
i++;
}
i++;
while (i < x.length) {
tx[i - 1] = x[i];
ty[i - 1] = y[i];
i++;
}
x = tx;
y = ty;
y2 = new float[ptsCount - 1];
xc1 = new float[ptsCount - 2];
xc2 = new float[ptsCount - 2];
yc1 = new float[ptsCount - 2];
yc2 = new float[ptsCount - 2];
selIndex = -1;
return true;
}
void mhr.appandroid.views.CurvesView.setCurvesChangeListener ( CurvesViewChangeListener  l)
inline

Definition at line 391 of file CurvesView.java.

{
listener = l;
}
void mhr.appandroid.views.CurvesView.setPoints ( float  pts[][])
inline

Definition at line 406 of file CurvesView.java.

{
int ptsCount = pts[0].length;
x = new float[ptsCount];
y = new float[ptsCount];
for (int i = 0; i < ptsCount; i++) {
x[i] = pts[0][i];
y[i] = 1 - pts[1][i];
}
y2 = new float[ptsCount];
xc1 = new float[ptsCount - 1];
xc2 = new float[ptsCount - 1];
yc1 = new float[ptsCount - 1];
yc2 = new float[ptsCount - 1];
invalidate();
}
int mhr.appandroid.views.CurvesView.xToGlob ( float  xVal)
inlineprotected

Definition at line 304 of file CurvesView.java.

{
return (int) (xVal * xLength + xOffset);
}
float mhr.appandroid.views.CurvesView.xToNorm ( float  xVal)
inlineprotected

Definition at line 312 of file CurvesView.java.

{
return (xVal - xOffset) / xLength;
}
void mhr.appandroid.views.CurvesView.y2ValsInit ( )
inlineprotected

Definition at line 337 of file CurvesView.java.

{
int i, k;
double p, qn, sig, un;
double[] u = new double[x.length];
int valsCount = x.length;
int lastVal = valsCount - 1;
y2[0] = 0.0f;
u[0] = 0.0;
for (i = 1; i < lastVal; i++) {
sig = (x[i] - x[i - 1]) / (x[i + 1] - x[i - 1]);
p = sig * y2[i - 1] + 2.0;
y2[i] =(float)((sig - 1.0) / p);
u[i] = (y[i + 1] - y[i]) / (x[i + 1] - x[i])
- (y[i] - y[i - 1]) / (x[i] - x[i - 1]);
u[i] = (6.0 * u[i] / (x[i + 1] - x[i - 1]) - sig * u[i - 1]) / p;
}
qn = un = 0.0;
y2[lastVal] =(float) ( (un - qn * u[valsCount - 2]) / (qn * y2[valsCount - 2] + 1.0));
for (k = valsCount - 2; k >= 0; k--) {
y2[k] = (float) (y2[k] * y2[k + 1] + u[k]);
}
}
int mhr.appandroid.views.CurvesView.yToGlob ( float  yVal)
inlineprotected

Definition at line 308 of file CurvesView.java.

{
return (int) (yVal * yLength + yOffset);
}
float mhr.appandroid.views.CurvesView.yToNorm ( float  yVal)
inlineprotected

Definition at line 316 of file CurvesView.java.

{
return (yVal - yOffset) / yLength;
}

Member Data Documentation

Rect mhr.appandroid.views.CurvesView.boundingRect
protected

Definition at line 205 of file CurvesView.java.

int mhr.appandroid.views.CurvesView.cHeight
protected

Definition at line 222 of file CurvesView.java.

Bitmap mhr.appandroid.views.CurvesView.cNormal
protected

Definition at line 203 of file CurvesView.java.

Bitmap mhr.appandroid.views.CurvesView.cPressed
protected

Definition at line 202 of file CurvesView.java.

Rect mhr.appandroid.views.CurvesView.cRect
protected

Definition at line 207 of file CurvesView.java.

ShapeDrawable mhr.appandroid.views.CurvesView.curve
protected

Definition at line 237 of file CurvesView.java.

Rect mhr.appandroid.views.CurvesView.curvesRect
protected

Definition at line 206 of file CurvesView.java.

int mhr.appandroid.views.CurvesView.cWidth
protected

Definition at line 221 of file CurvesView.java.

int mhr.appandroid.views.CurvesView.cXCenter
protected

Definition at line 223 of file CurvesView.java.

int mhr.appandroid.views.CurvesView.cYCenter
protected

Definition at line 224 of file CurvesView.java.

GestureDetector mhr.appandroid.views.CurvesView.detector
protected

Definition at line 200 of file CurvesView.java.

Paint mhr.appandroid.views.CurvesView.frame
protected

Definition at line 231 of file CurvesView.java.

CurvesViewChangeListener mhr.appandroid.views.CurvesView.listener = null
protected

Definition at line 235 of file CurvesView.java.

RectF mhr.appandroid.views.CurvesView.marginRect
protected

Definition at line 232 of file CurvesView.java.

Paint mhr.appandroid.views.CurvesView.marginRectPaint
protected

Definition at line 233 of file CurvesView.java.

float mhr.appandroid.views.CurvesView.minDelta = 0.001f
protected

Definition at line 239 of file CurvesView.java.

int mhr.appandroid.views.CurvesView.selIndex = -1
protected

Definition at line 229 of file CurvesView.java.

float [] mhr.appandroid.views.CurvesView.x
protected

Definition at line 212 of file CurvesView.java.

float [] mhr.appandroid.views.CurvesView.xc1
protected

Definition at line 213 of file CurvesView.java.

float [] mhr.appandroid.views.CurvesView.xc2
protected

Definition at line 214 of file CurvesView.java.

int mhr.appandroid.views.CurvesView.xLength
protected

Definition at line 209 of file CurvesView.java.

int mhr.appandroid.views.CurvesView.xOffset
protected

Definition at line 226 of file CurvesView.java.

float [] mhr.appandroid.views.CurvesView.y
protected

Definition at line 216 of file CurvesView.java.

float [] mhr.appandroid.views.CurvesView.y2
protected

Definition at line 217 of file CurvesView.java.

float [] mhr.appandroid.views.CurvesView.yc1
protected

Definition at line 218 of file CurvesView.java.

float [] mhr.appandroid.views.CurvesView.yc2
protected

Definition at line 219 of file CurvesView.java.

int mhr.appandroid.views.CurvesView.yLength
protected

Definition at line 210 of file CurvesView.java.

int mhr.appandroid.views.CurvesView.yOffset
protected

Definition at line 227 of file CurvesView.java.


The documentation for this class was generated from the following file: