OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / sdk / eclipse / plugins / com.android.ide.eclipse.adt / src / com / android / ide / eclipse / adt / editors / layout / gscripts / IGraphics.java
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.eclipse.org/org/documents/epl-v10.php
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.android.ide.eclipse.adt.editors.layout.gscripts;
18
19 /**
20  * Represents a graphical context that rules can use to draw on the canvas.
21  * <p/>
22  * The wrapper GC is only valid during the context of a paint operation.
23  * This means {@link IViewRule}s should not cache this object and call it at
24  * just about any time, it is only valid during a call that actually receives
25  * the GC wrapper.
26  */
27 public interface IGraphics {
28
29     /**
30      * Registers a color using 0x00rrggbb where each component is
31      * 0..0xFF.
32      * <p/>
33      * Transparency is handled separately using {@link #setAlpha(int)}.
34      * <p/>
35      * If the same color is registered twice, the same object will
36      * be returned.
37      */
38     IColor registerColor(int rgb);
39
40     /**
41      * Returns the height, in pixels, of the default font.
42      */
43     int getFontHeight();
44
45     /**
46      * Sets the foreground color. The foreground color is used
47      * for drawing operations including when text is drawn.
48      */
49     void setForeground(IColor color);
50
51     /**
52      * Sets the background color. The background color is used
53      * for fill operations.
54      */
55     void setBackground(IColor color);
56
57     /**
58      * Sets the receiver's alpha value which must be
59      * between 0 (transparent) and 255 (opaque).
60      * <p>
61      * This operation requires the operating system's advanced
62      * graphics subsystem which may not be available on some
63      * platforms.
64      *
65      * @return False if the GC doesn't support alpha.
66      */
67     boolean setAlpha(int alpha);
68
69     /**
70      * A line style for {@link IGraphics#setLineStyle(LineStyle)}.
71      */
72     enum LineStyle {
73         /** Style for solid lines. */
74         LINE_SOLID,
75         /** Style for dashed lines. */
76         LINE_DASH,
77         /** Style for dotted lines. */
78         LINE_DOT,
79         /** Style for alternating dash-dot lines. */
80         LINE_DASHDOT,
81         /** Style for dash-dot-dot lines. */
82         LINE_DASHDOTDOT
83     }
84
85     /**
86      * Sets the current line style.
87      */
88     void setLineStyle(LineStyle style);
89
90     /**
91      * Sets the width that will be used when drawing lines.
92      * The operation is ignored if <var>width</var> is less than 1.
93      */
94     void setLineWidth(int width);
95
96     /**
97      * Draws a line between 2 points, using the current foreground
98      * color and alpha.
99      */
100     void drawLine(int x1, int y1, int x2, int y2);
101     /**
102      * Draws a line between 2 points, using the current foreground
103      * color and alpha.
104      */
105     void drawLine(Point p1, Point p2);
106
107     /**
108      * Draws a rectangle outline between 2 points, using the current
109      * foreground color and alpha.
110      */
111     void drawRect(int x1, int y1, int x2, int y2);
112     /**
113      * Draws a rectangle outline between 2 points, using the current
114      * foreground color and alpha.
115      */
116     void drawRect(Point p1, Point p2);
117     /**
118      * Draws a rectangle outline between 2 points, using the current
119      * foreground color and alpha.
120      */
121     void drawRect(Rect r);
122
123     /**
124      * Fills a rectangle outline between 2 points, using the current
125      * background color and alpha.
126      */
127     void fillRect(int x1, int y1, int x2, int y2);
128     /**
129      * Fills a rectangle outline between 2 points, using the current
130      * background color and alpha.
131      */
132     void fillRect(Point p1, Point p2);
133     /**
134      * Fills a rectangle outline between 2 points, using the current
135      * background color and alpha.
136      */
137     void fillRect(Rect r);
138
139     /**
140      * Draws the given string, using the current foreground color.
141      * No tab expansion or carriage return processing will be performed.
142      *
143      * @param string the string to be drawn.
144      * @param x the x coordinate of the top left corner of the text.
145      * @param y the y coordinate of the top left corner of the text.
146      */
147     void drawString(String string, int x, int y);
148
149     /**
150      * Draws the given string, using the current foreground color.
151      * No tab expansion or carriage return processing will be performed.
152      *
153      * @param string the string to be drawn.
154      * @param topLeft the top left corner of the text.
155      */
156     void drawString(String string, Point topLeft);
157 }