안드로이드 개발 질문/답변
(글 수 45,052)
wheel 형 복불복 앱을 만들고 있습니다.
부채꼴 이미지와 항목 문자를 canvas로 출력을 하는데요
해당 좌표에 항목 문자를 가져 오려고 하는데 잘 되지를 않네요
private void drawRoulette(Canvas canvas)
{
int centerX = this.getWidth() / 2;
int centerY = this.getHeight() / 2;
int roulWidth = this.getWidth() - 10;
//int roulHeight = roulWidth;
int radius = roulWidth / 2;
RectF rt = new RectF(centerX-radius, centerY-radius, centerX+radius, centerY+radius);
float SliceAngle = 360.0f / mSlices.size();
double textStartX = radius - 8;
double textStartY = 0.0;
//int PrevColorIdx = -1;
int CurColorIdx = -1;
for(int i=0; i<mSlices.size(); startAngle+=SliceAngle, i++)
{
CurColorIdx = i%ColorList.length;
Pnt.setColor(ColorList[CurColorIdx]);
Pnt.setStyle(Paint.Style.FILL);
canvas.drawArc(rt, startAngle, SliceAngle, true, Pnt);
float curHalfAngle = (startAngle + (SliceAngle / 2));
// x' = x * cosθ + y * (-sinθ)
double txtStartX = Math.cos(Math.toRadians(curHalfAngle)) * textStartX;
txtStartX = txtStartX + Math.sin(Math.toRadians(curHalfAngle)) * textStartY * (-1);
txtStartX += centerX;
// y' = x * sinθ + y * cosθ
double txtStartY= Math.sin(Math.toRadians(curHalfAngle)) * textStartX;
txtStartY = txtStartY + Math.cos(Math.toRadians(curHalfAngle)) * textStartY;
txtStartY += centerY;
textPath.reset();
Pnt.setColor(Color.WHITE);
Pnt.setStrokeWidth(3);
textPath.moveTo((int)txtStartX, (int)txtStartY);
textPath.lineTo(centerX, centerY);
canvas.drawTextOnPath(mSlices.get(i), textPath, 0, 0, Pnt);
}
}
이 소스로 룰렛을 완성시키고 실행 시키면 룰렛이 돌아가다가 멈추는데요
멈추면 해당 지점의 문자를 가져와서 뿌려주려고 합니다. 그 걸린 항목의 문자를 어떻게 가져오면 될까요?
벌써 일주일째 여기서 해매고 있네요.
많은 도움 부탁드려요 ^^
부채꼴 이미지와 항목 문자를 canvas로 출력을 하는데요
해당 좌표에 항목 문자를 가져 오려고 하는데 잘 되지를 않네요
private void drawRoulette(Canvas canvas)
{
int centerX = this.getWidth() / 2;
int centerY = this.getHeight() / 2;
int roulWidth = this.getWidth() - 10;
//int roulHeight = roulWidth;
int radius = roulWidth / 2;
RectF rt = new RectF(centerX-radius, centerY-radius, centerX+radius, centerY+radius);
float SliceAngle = 360.0f / mSlices.size();
double textStartX = radius - 8;
double textStartY = 0.0;
//int PrevColorIdx = -1;
int CurColorIdx = -1;
for(int i=0; i<mSlices.size(); startAngle+=SliceAngle, i++)
{
CurColorIdx = i%ColorList.length;
Pnt.setColor(ColorList[CurColorIdx]);
Pnt.setStyle(Paint.Style.FILL);
canvas.drawArc(rt, startAngle, SliceAngle, true, Pnt);
float curHalfAngle = (startAngle + (SliceAngle / 2));
// x' = x * cosθ + y * (-sinθ)
double txtStartX = Math.cos(Math.toRadians(curHalfAngle)) * textStartX;
txtStartX = txtStartX + Math.sin(Math.toRadians(curHalfAngle)) * textStartY * (-1);
txtStartX += centerX;
// y' = x * sinθ + y * cosθ
double txtStartY= Math.sin(Math.toRadians(curHalfAngle)) * textStartX;
txtStartY = txtStartY + Math.cos(Math.toRadians(curHalfAngle)) * textStartY;
txtStartY += centerY;
textPath.reset();
Pnt.setColor(Color.WHITE);
Pnt.setStrokeWidth(3);
textPath.moveTo((int)txtStartX, (int)txtStartY);
textPath.lineTo(centerX, centerY);
canvas.drawTextOnPath(mSlices.get(i), textPath, 0, 0, Pnt);
}
}
이 소스로 룰렛을 완성시키고 실행 시키면 룰렛이 돌아가다가 멈추는데요
멈추면 해당 지점의 문자를 가져와서 뿌려주려고 합니다. 그 걸린 항목의 문자를 어떻게 가져오면 될까요?
벌써 일주일째 여기서 해매고 있네요.
많은 도움 부탁드려요 ^^