OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef GFX_CANVAS_2_H_ | |
6 #define GFX_CANVAS_2_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "gfx/native_widget_types.h" | |
11 // TODO(beng): remove this include when we no longer depend on SkTypes. | |
12 #include "skia/ext/platform_canvas.h" | |
13 | |
14 namespace gfx { | |
15 | |
16 class Canvas; | |
17 class Font; | |
18 class Rect; | |
19 | |
20 // TODO(beng): documentation. | |
21 class Canvas2 { | |
22 public: | |
23 // Specifies the alignment for text rendered with the DrawStringInt method. | |
24 enum { | |
25 TEXT_ALIGN_LEFT = 1, | |
26 TEXT_ALIGN_CENTER = 2, | |
27 TEXT_ALIGN_RIGHT = 4, | |
28 TEXT_VALIGN_TOP = 8, | |
29 TEXT_VALIGN_MIDDLE = 16, | |
30 TEXT_VALIGN_BOTTOM = 32, | |
31 | |
32 // Specifies the text consists of multiple lines. | |
33 MULTI_LINE = 64, | |
34 | |
35 // By default DrawStringInt does not process the prefix ('&') character | |
36 // specially. That is, the string "&foo" is rendered as "&foo". When | |
37 // rendering text from a resource that uses the prefix character for | |
38 // mnemonics, the prefix should be processed and can be rendered as an | |
39 // underline (SHOW_PREFIX), or not rendered at all (HIDE_PREFIX). | |
40 SHOW_PREFIX = 128, | |
41 HIDE_PREFIX = 256, | |
42 | |
43 // Prevent ellipsizing | |
44 NO_ELLIPSIS = 512, | |
45 | |
46 // Specifies if words can be split by new lines. | |
47 // This only works with MULTI_LINE. | |
48 CHARACTER_BREAK = 1024, | |
49 | |
50 // Instructs DrawStringInt() to render the text using RTL directionality. | |
51 // In most cases, passing this flag is not necessary because information | |
52 // about the text directionality is going to be embedded within the string | |
53 // in the form of special Unicode characters. However, we don't insert | |
54 // directionality characters into strings if the locale is LTR because some | |
55 // platforms (for example, an English Windows XP with no RTL fonts | |
56 // installed) don't support these characters. Thus, this flag should be | |
57 // used to render text using RTL directionality when the locale is LTR. | |
58 FORCE_RTL_DIRECTIONALITY = 2048, | |
59 }; | |
60 | |
61 virtual ~Canvas2() {} | |
62 | |
63 // Creates an empty canvas. Must be initialized before it can be used. | |
64 static Canvas2* CreateCanvas(); | |
65 | |
66 // Creates a canvas with the specified size. | |
67 static Canvas2* CreateCanvas(int width, int height, bool is_opaque); | |
68 | |
69 // Retrieves the clip rectangle and sets it in the specified rectangle if any. | |
70 // Returns true if the clip rect is non-empty. | |
71 virtual bool GetClipRect(gfx::Rect* clip_rect) = 0; | |
72 | |
73 // Wrapper function that takes integer arguments. | |
74 // Returns true if the clip is non-empty. | |
75 // See clipRect for specifics. | |
76 virtual bool ClipRectInt(int x, int y, int w, int h) = 0; | |
77 | |
78 // Test whether the provided rectangle intersects the current clip rect. | |
79 virtual bool IntersectsClipRectInt(int x, int y, int w, int h) = 0; | |
80 | |
81 // Wrapper function that takes integer arguments. | |
82 // See translate() for specifics. | |
83 virtual void TranslateInt(int x, int y) = 0; | |
84 | |
85 // Wrapper function that takes integer arguments. | |
86 // See scale() for specifics. | |
87 virtual void ScaleInt(int x, int y) = 0; | |
88 | |
89 // Fills the given rectangle with the given paint's parameters. | |
90 virtual void FillRectInt(int x, int y, int w, int h, | |
91 const SkPaint& paint) = 0; | |
92 | |
93 // Fills the specified region with the specified color using a transfer | |
94 // mode of SkXfermode::kSrcOver_Mode. | |
95 virtual void FillRectInt(const SkColor& color, int x, int y, int w, | |
96 int h) = 0; | |
97 | |
98 // Draws a single pixel rect in the specified region with the specified | |
99 // color, using a transfer mode of SkXfermode::kSrcOver_Mode. | |
100 // | |
101 // NOTE: if you need a single pixel line, use DraLineInt. | |
102 virtual void DrawRectInt(const SkColor& color, int x, int y, int w, | |
103 int h) = 0; | |
104 | |
105 // Draws a single pixel rect in the specified region with the specified | |
106 // color and transfer mode. | |
107 // | |
108 // NOTE: if you need a single pixel line, use DraLineInt. | |
109 virtual void DrawRectInt(const SkColor& color, int x, int y, int w, int h, | |
110 SkXfermode::Mode mode) = 0; | |
111 | |
112 // Draws a single pixel line with the specified color. | |
113 virtual void DrawLineInt(const SkColor& color, int x1, int y1, int x2, | |
114 int y2) = 0; | |
115 | |
116 // Draws a bitmap with the origin at the specified location. The upper left | |
117 // corner of the bitmap is rendered at the specified location. | |
118 virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y) = 0; | |
119 | |
120 // Draws a bitmap with the origin at the specified location, using the | |
121 // specified paint. The upper left corner of the bitmap is rendered at the | |
122 // specified location. | |
123 virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y, | |
124 const SkPaint& paint) = 0; | |
125 | |
126 // Draws a portion of a bitmap in the specified location. The src parameters | |
127 // correspond to the region of the bitmap to draw in the region defined | |
128 // by the dest coordinates. | |
129 // | |
130 // If the width or height of the source differs from that of the destination, | |
131 // the bitmap will be scaled. When scaling down, it is highly recommended | |
132 // that you call buildMipMap(false) on your bitmap to ensure that it has | |
133 // a mipmap, which will result in much higher-quality output. Set |filter| | |
134 // to use filtering for bitmaps, otherwise the nearest-neighbor algorithm | |
135 // is used for resampling. | |
136 // | |
137 // An optional custom SkPaint can be provided. | |
138 virtual void DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, | |
139 int src_w, int src_h, int dest_x, int dest_y, | |
140 int dest_w, int dest_h, bool filter) = 0; | |
141 virtual void DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, | |
142 int src_w, int src_h, int dest_x, int dest_y, | |
143 int dest_w, int dest_h, bool filter, | |
144 const SkPaint& paint) = 0; | |
145 | |
146 // Draws text with the specified color, font and location. The text is | |
147 // aligned to the left, vertically centered, clipped to the region. If the | |
148 // text is too big, it is truncated and '...' is added to the end. | |
149 virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, | |
150 const SkColor& color, int x, int y, int w, | |
151 int h) = 0; | |
152 virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, | |
153 const SkColor& color, | |
154 const gfx::Rect& display_rect) = 0; | |
155 | |
156 // Draws text with the specified color, font and location. The last argument | |
157 // specifies flags for how the text should be rendered. It can be one of | |
158 // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT. | |
159 virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, | |
160 const SkColor& color, int x, int y, int w, int h, | |
161 int flags) = 0; | |
162 | |
163 // Draws a dotted gray rectangle used for focus purposes. | |
164 virtual void DrawFocusRect(int x, int y, int width, int height) = 0; | |
165 | |
166 // Tiles the image in the specified region. | |
167 virtual void TileImageInt(const SkBitmap& bitmap, int x, int y, int w, | |
168 int h) = 0; | |
169 virtual void TileImageInt(const SkBitmap& bitmap, int src_x, int src_y, | |
170 int dest_x, int dest_y, int w, int h) = 0; | |
171 | |
172 // Extracts a bitmap from the contents of this canvas. | |
173 virtual SkBitmap ExtractBitmap() const = 0; | |
174 | |
175 // TODO(beng): remove this once we don't need to use any skia-specific methods | |
176 // through this interface. | |
177 // A quick and dirty way to obtain the underlying SkCanvas. | |
178 virtual Canvas* AsCanvas() { return NULL; } | |
179 }; | |
180 | |
181 class CanvasPaint2 { | |
182 public: | |
183 virtual ~CanvasPaint2() {} | |
184 | |
185 // Creates a canvas that paints to |view| when it is destroyed. The canvas is | |
186 // sized to the client area of |view|. | |
187 static CanvasPaint2* CreateCanvasPaint(gfx::NativeView view); | |
188 | |
189 // Returns true if the canvas has an invalid rect that needs to be repainted. | |
190 virtual bool IsValid() const = 0; | |
191 | |
192 // Returns the rectangle that is invalid. | |
193 virtual gfx::Rect GetInvalidRect() const = 0; | |
194 | |
195 // Returns the underlying Canvas2. | |
196 virtual Canvas2* AsCanvas2() = 0; | |
197 }; | |
198 | |
199 } // namespace gfx; | |
200 | |
201 #endif // GFX_CANVAS_2_H_ | |
OLD | NEW |