| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef GFX_CANVAS_H_ | 5 #ifndef GFX_CANVAS_H_ |
| 6 #define GFX_CANVAS_H_ | 6 #define GFX_CANVAS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include "gfx/canvas_skia.h" |
| 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 | 9 |
| 14 namespace gfx { | 10 namespace gfx { |
| 15 | 11 |
| 16 class CanvasSkia; | 12 // Temporary compatibility shim, remove once Canvas2->Canvas. |
| 17 class Font; | 13 class Canvas : public CanvasSkia { |
| 18 class Rect; | 14 public: |
| 15 Canvas(int width, int height, bool is_opaque) |
| 16 : CanvasSkia(width, height, is_opaque) { |
| 17 } |
| 18 Canvas() : CanvasSkia() {} |
| 19 | 19 |
| 20 // TODO(beng): documentation. | 20 // Overridden from Canvas2: |
| 21 class Canvas { | 21 Canvas* AsCanvas() { |
| 22 public: | 22 return this; |
| 23 // Specifies the alignment for text rendered with the DrawStringInt method. | 23 } |
| 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 | 24 |
| 32 // Specifies the text consists of multiple lines. | 25 private: |
| 33 MULTI_LINE = 64, | 26 DISALLOW_COPY_AND_ASSIGN(Canvas); |
| 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 ~Canvas() {} | |
| 62 | |
| 63 // Creates an empty canvas. Must be initialized before it can be used. | |
| 64 static Canvas* CreateCanvas(); | |
| 65 | |
| 66 // Creates a canvas with the specified size. | |
| 67 static Canvas* 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 // TODO(beng): remove this once we don't need to use any skia-specific methods | |
| 173 // through this interface. | |
| 174 // A quick and dirty way to obtain the underlying SkCanvas. | |
| 175 virtual CanvasSkia* AsCanvasSkia() { return NULL; } | |
| 176 virtual const CanvasSkia* AsCanvasSkia() const { return NULL; } | |
| 177 }; | 27 }; |
| 178 | 28 |
| 179 class CanvasPaint { | 29 } |
| 180 public: | |
| 181 virtual ~CanvasPaint() {} | |
| 182 | |
| 183 // Creates a canvas that paints to |view| when it is destroyed. The canvas is | |
| 184 // sized to the client area of |view|. | |
| 185 static CanvasPaint* CreateCanvasPaint(gfx::NativeView view); | |
| 186 | |
| 187 // Returns true if the canvas has an invalid rect that needs to be repainted. | |
| 188 virtual bool IsValid() const = 0; | |
| 189 | |
| 190 // Returns the rectangle that is invalid. | |
| 191 virtual gfx::Rect GetInvalidRect() const = 0; | |
| 192 | |
| 193 // Returns the underlying Canvas. | |
| 194 virtual Canvas* AsCanvas() = 0; | |
| 195 }; | |
| 196 | |
| 197 } // namespace gfx; | |
| 198 | 30 |
| 199 #endif // GFX_CANVAS_H_ | 31 #endif // GFX_CANVAS_H_ |
| OLD | NEW |