aboutsummaryrefslogtreecommitdiffstats
path: root/rule_api/src/com/android/ide/common/api/IGraphics.java
blob: 1a7f64a03afff638d34d126943247813b0e54ee9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Eclipse Public License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.eclipse.org/org/documents/epl-v10.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.ide.common.api;

import com.android.annotations.NonNull;
import com.google.common.annotations.Beta;

import java.util.List;

/**
 * Represents a graphical context that rules can use to draw on the canvas.
 * <p/>
 * The wrapper GC is only valid during the context of a paint operation.
 * This means {@link IViewRule}s should not cache this object and call it at
 * just about any time, it is only valid during a call that actually receives
 * the GC wrapper.
 * <p>
 * <b>NOTE: This is not a public or final API; if you rely on this be prepared
 * to adjust your code for the next tools release.</b>
 * </p>
 */
@Beta
public interface IGraphics {

    /**
     * Draws a line between 2 points, using the current foreground color and
     * alpha.
     */
    void drawLine(int x1, int y1, int x2, int y2);

    /**
     * Draws a line between 2 points, using the current foreground color and
     * alpha.
     */
    void drawLine(@NonNull Point p1, @NonNull Point p2);

    /**
     * Draws an arrow from (x1, y1) to (x2, y2).
     *
     * @param x1 The x coordinate of the beginning of the arrow
     * @param y1 The y coordinate of the beginning of the arrow
     * @param x2 The x coordinate of the end (point) of the arrow
     * @param y2 The y coordinate of the end (point) of the arrow
     * @param size The size of the arrowhead
     */
    void drawArrow(int x1, int y1, int x2, int y2, int size);

    /**
     * Draws a dot at the given position.
     *
     * @param x The x coordinate of the dot
     * @param y The y coordinate of the dot
     */
    void drawPoint(int x, int y);

    /**
     * Draws a rectangle outline between 2 points, using the current foreground
     * color and alpha.
     */
    void drawRect(int x1, int y1, int x2, int y2);

    /**
     * Draws a rectangle outline between 2 points, using the current foreground
     * color and alpha.
     */
    void drawRect(@NonNull Point p1, @NonNull Point p2);

    /**
     * Draws a rectangle outline between 2 points, using the current foreground
     * color and alpha.
     */
    void drawRect(@NonNull Rect r);

    /**
     * Fills a rectangle outline between 2 points, using the current background
     * color and alpha.
     */
    void fillRect(int x1, int y1, int x2, int y2);

    /**
     * Fills a rectangle outline between 2 points, using the current background
     * color and alpha.
     */
    void fillRect(@NonNull Point p1, @NonNull Point p2);

    /**
     * Fills a rectangle outline between 2 points, using the current background
     * color and alpha.
     */
    void fillRect(@NonNull Rect r);

    /**
     * Draws the given string, using the current foreground color. No tab
     * expansion or carriage return processing will be performed.
     *
     * @param string the string to be drawn.
     * @param x the x coordinate of the top left corner of the text.
     * @param y the y coordinate of the top left corner of the text.
     */
    void drawString(@NonNull String string, int x, int y);

    /**
     * Draws the given string, using the current foreground color. No tab
     * expansion or carriage return processing will be performed.
     *
     * @param string the string to be drawn.
     * @param topLeft the top left corner of the text.
     */
    void drawString(@NonNull String string, @NonNull Point topLeft);

    /**
     * Draw the given strings, using the current stroke color and alpha for the
     * text, and the current fill color and alpha for a rectangle behind the
     * bounding box fitting all the lines of text. Each subsequent string is
     * drawn on consecutive lines below the previous string.
     *
     * @param x The left edge to start each string at
     * @param y The top position of the first string; subsequent strings are
     *            painted on lines below
     * @param strings An array of labels to be displayed (should not be null).
     *            The actual String used is the {@link Object#toString()} value
     *            of each list item.
     */
    void drawBoxedStrings(int x, int y, @NonNull List<?> strings);

    /**
     * Set up the graphics context to use the given style for subsequent drawing
     * operations.
     *
     * @param style The drawing style to be used. May not be null.
     */
    void useStyle(@NonNull DrawingStyle style);

    /**
     * Registers a color using 0x00rrggbb where each component is 0..0xFF.
     * <p/>
     * Transparency is handled separately using {@link #setAlpha(int)}.
     * <p/>
     * If the same color is registered twice, the same object will be returned.
     * <p/>
     * NOTE: It's preferable to use {@link #useStyle(DrawingStyle)} if possible
     * to ensure that your colors work properly across multiple current and
     * future themes.
     */
    @NonNull
    IColor registerColor(int rgb);

    /**
     * Returns the height, in pixels, of the default font.
     */
    int getFontHeight();

    /**
     * Returns the current foreground color.
     * The foreground color is used for drawing operations including when text is drawn.
     */
    @NonNull
    IColor getForeground();

    /**
     * Sets the foreground color. The foreground color is used for drawing
     * operations including when text is drawn.
     */
    void setForeground(@NonNull IColor color);

    /**
     * Returns the current background color. The background color is used for
     * fill operations.
     */
    @NonNull
    IColor getBackground();

    /**
     * Sets the background color. The background color is used for fill
     * operations.
     */
    void setBackground(@NonNull IColor color);

    /**
     * Returns the current alpha value (varies between 0 for transparent and 255
     * for opaque).
     *
     * @return The current alpha value in use
     */
    int getAlpha();

    /**
     * Sets the receiver's alpha value which must be
     * between 0 (transparent) and 255 (opaque).
     * <p>
     * This operation requires the operating system's advanced
     * graphics subsystem which may not be available on some
     * platforms.
     * <p>
     * TODO: Consider removing this method; it will usually be ignored because
     * most graphics operations apply the alpha from the current drawing style
     */
    void setAlpha(int alpha);

    /**
     * A line style for {@link IGraphics#setLineStyle(LineStyle)}.
     */
    enum LineStyle {
        /** Style for solid lines. */
        LINE_SOLID,
        /** Style for dashed lines. */
        LINE_DASH,
        /** Style for dotted lines. */
        LINE_DOT,
        /** Style for alternating dash-dot lines. */
        LINE_DASHDOT,
        /** Style for dash-dot-dot lines. */
        LINE_DASHDOTDOT
    }

    /**
     * Sets the current line style.
     */
    void setLineStyle(@NonNull LineStyle style);

    /**
     * Sets the width that will be used when drawing lines.
     * The operation is ignored if <var>width</var> is less than 1.
     */
    void setLineWidth(int width);
}