OLD | NEW |
---|---|
1 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_VIEW_FILTER_H_ | 1 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_VIEW_FILTER_H_ |
2 #define CHROME_BROWSER_CHROMEOS_LOGIN_VIEW_FILTER_H_ | 2 #define CHROME_BROWSER_CHROMEOS_LOGIN_VIEW_FILTER_H_ |
3 | 3 |
4 #include "gfx/canvas.h" | 4 #include "gfx/canvas.h" |
5 #include "gfx/canvas_skia.h" | 5 #include "gfx/canvas_skia.h" |
6 #include "gfx/rect.h" | 6 #include "gfx/rect.h" |
7 | 7 |
8 namespace chromeos { | 8 namespace chromeos { |
9 | 9 |
10 namespace rounded_view { | 10 namespace rounded_view { |
11 | 11 |
12 // Corner radius of the RoundedView. | 12 // Corner radius of the RoundedView. |
13 const int kCornerRadius = 5; | 13 const SkScalar kCornerRadius = SkIntToScalar(5); |
14 | 14 |
15 // Stroke width to be used by the RoundedView. | 15 // Stroke width to be used by the RoundedView. |
16 const int kStrokeWidth = 1; | 16 const SkScalar kStrokeWidth = SkIntToScalar(1); |
17 | 17 |
18 // Color of the inner frame of the RoundedView. | 18 // Color of the inner frame of the RoundedView. |
19 const SkColor kInnerFrameColor = SK_ColorWHITE; | 19 const SkColor kInnerFrameColor = SK_ColorWHITE; |
20 | 20 |
21 // Color of the outer frame of the RoundedView. | 21 // Color of the outer frame of the RoundedView. |
22 const SkColor kOuterFrameColor = 0xFF555555; | 22 const SkColor kOuterFrameColor = 0xFF555555; |
23 | 23 |
24 } // namespace rounded_view | 24 } // namespace rounded_view |
25 | 25 |
26 // Class that sets up the round rectangle as a clip region of the view. | 26 // Class that sets up the round rectangle as a clip region of the view. |
(...skipping 19 matching lines...) Expand all Loading... | |
46 virtual SkRect GetViewRect() const; | 46 virtual SkRect GetViewRect() const; |
47 | 47 |
48 // Draws custom frame for the view. | 48 // Draws custom frame for the view. |
49 virtual void DrawFrame(gfx::Canvas* canvas); | 49 virtual void DrawFrame(gfx::Canvas* canvas); |
50 }; | 50 }; |
51 | 51 |
52 // RoundedView implementation. | 52 // RoundedView implementation. |
53 | 53 |
54 template <typename C> | 54 template <typename C> |
55 void RoundedView<C>::ProcessPaint(gfx::Canvas* canvas) { | 55 void RoundedView<C>::ProcessPaint(gfx::Canvas* canvas) { |
56 //canvas->AsCanvasSkia()->drawColor(0xFFFFFFFF); | |
Nikita (slow)
2010/12/07 09:32:40
Remove?
altimofeev
2010/12/10 10:25:25
Done.
| |
56 // Setup clip region. | 57 // Setup clip region. |
57 canvas->Save(); | 58 canvas->Save(); |
58 canvas->AsCanvasSkia()->clipPath(GetClipPath()); | 59 canvas->AsCanvasSkia()->clipPath(GetClipPath()); |
59 // Do original painting. | 60 // Do original painting. |
60 C::ProcessPaint(canvas); | 61 C::ProcessPaint(canvas); |
61 canvas->Restore(); | 62 canvas->Restore(); |
62 // Add frame. | 63 // Add frame. |
63 DrawFrame(canvas); | 64 DrawFrame(canvas); |
64 } | 65 } |
65 | 66 |
66 template <typename C> | 67 template <typename C> |
67 SkPath RoundedView<C>::GetClipPath() const { | 68 SkPath RoundedView<C>::GetClipPath() const { |
68 SkPath round_view; | 69 SkPath round_view; |
69 SkRect view_rect = GetViewRect(); | 70 SkRect view_rect = GetViewRect(); |
70 view_rect.inset(2 * rounded_view::kStrokeWidth, | 71 view_rect.inset(2 * rounded_view::kStrokeWidth, |
71 2 * rounded_view::kStrokeWidth); | 72 2 * rounded_view::kStrokeWidth); |
73 // 3 is used instead of 2 to avoid empty points between the clip and | |
74 // the frame. | |
72 round_view.addRoundRect( | 75 round_view.addRoundRect( |
73 GetViewRect(), rounded_view::kCornerRadius, rounded_view::kCornerRadius); | 76 view_rect, |
77 rounded_view::kCornerRadius - 3 * rounded_view::kStrokeWidth, | |
78 rounded_view::kCornerRadius - 3 * rounded_view::kStrokeWidth); | |
79 | |
74 return round_view; | 80 return round_view; |
75 } | 81 } |
76 | 82 |
77 template <typename C> | 83 template <typename C> |
78 SkRect RoundedView<C>::GetViewRect() const { | 84 SkRect RoundedView<C>::GetViewRect() const { |
79 gfx::Rect bounds = RoundedView<C>::GetLocalBounds(false); | 85 gfx::Rect bounds = RoundedView<C>::GetLocalBounds(false); |
80 SkRect view_rect; | 86 SkRect view_rect; |
81 view_rect.iset(bounds.x(), bounds.y(), | 87 view_rect.iset(bounds.x(), bounds.y(), |
82 bounds.x() + bounds.width(), | 88 bounds.x() + bounds.width(), |
83 bounds.y() + bounds.height()); | 89 bounds.y() + bounds.height()); |
84 return view_rect; | 90 return view_rect; |
85 } | 91 } |
86 | 92 |
87 template <typename C> | 93 template <typename C> |
88 void RoundedView<C>::DrawFrame(gfx::Canvas* canvas) { | 94 void RoundedView<C>::DrawFrame(gfx::Canvas* canvas) { |
89 SkPaint paint; | 95 SkPaint paint; |
90 paint.setStyle(SkPaint::kStroke_Style); | 96 paint.setStyle(SkPaint::kStroke_Style); |
91 paint.setStrokeWidth(rounded_view::kStrokeWidth); | 97 paint.setStrokeWidth(rounded_view::kStrokeWidth); |
92 paint.setAntiAlias(true); | 98 paint.setAntiAlias(true); |
93 SkRect view_rect = GetViewRect(); | 99 SkRect view_rect = GetViewRect(); |
94 | 100 |
101 // Used to make nested rounded rects look better. | |
102 const SkScalar kOriginShift = 1.0; | |
103 const SkScalar kDelta = 0.3; | |
104 | |
95 // Draw inner frame. | 105 // Draw inner frame. |
106 view_rect.fLeft -= kOriginShift; | |
107 view_rect.fTop -= kOriginShift; | |
96 view_rect.inset(rounded_view::kStrokeWidth, rounded_view::kStrokeWidth); | 108 view_rect.inset(rounded_view::kStrokeWidth, rounded_view::kStrokeWidth); |
97 paint.setColor(rounded_view::kInnerFrameColor); | 109 paint.setColor(rounded_view::kInnerFrameColor); |
98 canvas->AsCanvasSkia()->drawRoundRect(view_rect, rounded_view::kCornerRadius, | 110 canvas->AsCanvasSkia()-> |
99 rounded_view::kCornerRadius, paint); | 111 drawRoundRect(view_rect, |
112 rounded_view::kCornerRadius - rounded_view::kStrokeWidth, | |
113 rounded_view::kCornerRadius - rounded_view::kStrokeWidth, | |
114 paint); | |
100 | 115 |
101 // Draw outer frame. | 116 // Draw outer frame. |
102 view_rect.inset(-rounded_view::kStrokeWidth, -rounded_view::kStrokeWidth); | 117 view_rect.fLeft -= kDelta; |
118 view_rect.fTop -= kDelta; | |
119 view_rect.offset(rounded_view::kStrokeWidth - kDelta, | |
120 rounded_view::kStrokeWidth - kDelta); | |
103 paint.setColor(rounded_view::kOuterFrameColor); | 121 paint.setColor(rounded_view::kOuterFrameColor); |
104 canvas->AsCanvasSkia()->drawRoundRect(view_rect, rounded_view::kCornerRadius, | 122 canvas->AsCanvasSkia()->drawRoundRect(view_rect, rounded_view::kCornerRadius, |
105 rounded_view::kCornerRadius, paint); | 123 rounded_view::kCornerRadius, paint); |
106 } | 124 } |
107 | 125 |
108 } | 126 } |
109 | 127 |
110 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_VIEW_FILTER_H_ | 128 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_VIEW_FILTER_H_ |
OLD | NEW |