LibreOffice Module android (master) 1
GraphicSelectionHandle.java
Go to the documentation of this file.
1/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9package org.libreoffice.canvas;
10
11import android.graphics.Canvas;
12import android.graphics.Color;
13import android.graphics.Paint;
14import android.graphics.PointF;
15import android.graphics.RectF;
16
26 private final float HIT_AREA_INFLATE_FACTOR = 1.75f;
27
29 public PointF mPosition = new PointF();
30 private float mRadius = 20.0f;
31 private Paint mStrokePaint = new Paint();
32 private Paint mFillPaint = new Paint();
34 private RectF mHitRect = new RectF();
35 private boolean mSelected = false;
36
43
44 mStrokePaint.setStyle(Paint.Style.STROKE);
45 mStrokePaint.setColor(Color.GRAY);
46 mStrokePaint.setStrokeWidth(3);
47 mStrokePaint.setAntiAlias(true);
48
49 mFillPaint.setStyle(Paint.Style.FILL);
50 mFillPaint.setColor(Color.WHITE);
51 mFillPaint.setAlpha(200);
52 mFillPaint.setAntiAlias(true);
53
54 mSelectedFillPaint.setStyle(Paint.Style.FILL);
55 mSelectedFillPaint.setColor(Color.GRAY);
56 mSelectedFillPaint.setAlpha(200);
57 mSelectedFillPaint.setAntiAlias(true);
58 }
59
65 return mHandlePosition;
66 }
67
73 @Override
74 public void onDraw(Canvas canvas) {
75 if (mSelected) {
77 } else {
79 }
80 }
81
85 private void drawFilledCircle(Canvas canvas, float x, float y, float radius, Paint strokePaint, Paint fillPaint) {
86 canvas.drawCircle(x, y, radius, fillPaint);
87 canvas.drawCircle(x, y, radius, strokePaint);
88 }
89
93 public void reposition(float x, float y) {
94 mPosition.x = x;
95 mPosition.y = y;
96
97 // inflate the radius by HIT_AREA_INFLATE_FACTOR
98 float inflatedRadius = mRadius * HIT_AREA_INFLATE_FACTOR;
99
100 // reposition the hit area rectangle
101 mHitRect.left = mPosition.x - inflatedRadius;
102 mHitRect.right = mPosition.x + inflatedRadius;
103 mHitRect.top = mPosition.y - inflatedRadius;
104 mHitRect.bottom = mPosition.y + inflatedRadius;
105 }
106
111 @Override
112 public boolean onHitTest(float x, float y) {
113 return mHitRect.contains(x, y);
114 }
115
119 public void select() {
120 mSelected = true;
121 }
122
126 public void reset() {
127 mSelected = false;
128 }
129
134 public enum HandlePosition {
142 LEFT
144}
145
146/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Common implementation to canvas elements.
This class is responsible to draw the selection handles, track the handle position and perform a hit ...
GraphicSelectionHandle(HandlePosition position)
Construct the handle - set the handle position on the selection.
void onDraw(Canvas canvas)
Draws the handle to the canvas.
void reposition(float x, float y)
Viewport has changed, reposition the handle to the input coordinates.
final float HIT_AREA_INFLATE_FACTOR
The factor used to inflate the hit area.
void reset()
Reset the selection for the handle.
boolean onHitTest(float x, float y)
Hit test for the handle.
HandlePosition getHandlePosition()
The position of the handle.
void drawFilledCircle(Canvas canvas, float x, float y, float radius, Paint strokePaint, Paint fillPaint)
Draw a filled and stroked circle to the canvas.
float y
float x
def position(n=-1)
const sal_uInt32 LEFT