Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: ash/touch/touch_observer_hud.cc

Issue 10399061: ash: Make the touchy heads-up display more colorful/useful. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/touch/touch_observer_hud.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "ash/touch/touch_observer_hud.h" 5 #include "ash/touch/touch_observer_hud.h"
6 6
7 #include "ash/shell_window_ids.h" 7 #include "ash/shell_window_ids.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "third_party/skia/include/core/SkPath.h"
11 #include "third_party/skia/include/core/SkXfermode.h"
10 #include "ui/aura/event.h" 12 #include "ui/aura/event.h"
13 #include "ui/gfx/canvas.h"
14 #include "ui/gfx/monitor.h"
15 #include "ui/gfx/rect.h"
16 #include "ui/gfx/screen.h"
17 #include "ui/gfx/size.h"
11 #include "ui/views/background.h" 18 #include "ui/views/background.h"
12 #include "ui/views/controls/label.h" 19 #include "ui/views/controls/label.h"
13 #include "ui/views/layout/box_layout.h" 20 #include "ui/views/layout/box_layout.h"
14 #include "ui/views/widget/widget.h" 21 #include "ui/views/widget/widget.h"
15 22
16 namespace ash { 23 namespace ash {
17 namespace internal { 24 namespace internal {
18 25
26 const int kMaxPaths = 15;
27 const int kScale = 10;
28 const int kColors[] = {
29 SK_ColorYELLOW,
30 SK_ColorGREEN,
31 SK_ColorRED,
32 SK_ColorBLUE,
33 SK_ColorMAGENTA,
34 SK_ColorCYAN,
35 SK_ColorWHITE,
36 SK_ColorBLACK
37 };
38
39 class TouchHudCanvas : public views::View {
40 public:
41 explicit TouchHudCanvas(TouchObserverHUD* owner)
42 : owner_(owner),
43 path_index_(0),
44 color_index_(0) {
45 gfx::Monitor monitor = gfx::Screen::GetPrimaryMonitor();
46 gfx::Rect bounds = monitor.bounds();
47 size_.set_width(bounds.width() / kScale);
48 size_.set_height(bounds.height() / kScale);
49 }
50
51 virtual ~TouchHudCanvas() {}
52
53 void Start(int id, const gfx::Point& point) {
54 paths_[path_index_].reset();
55 paths_[path_index_].moveTo(SkIntToScalar(point.x() / kScale),
56 SkIntToScalar(point.y() / kScale));
57 colors_[path_index_] = kColors[color_index_];
58 color_index_ = (color_index_ + 1) % arraysize(kColors);
59
60 touch_id_to_path_[id] = path_index_;
61 path_index_ = (path_index_ + 1) % kMaxPaths;
62 SchedulePaint();
63 }
64
65 void Update(int id, gfx::Point& to) {
66 SkPoint last;
67 int path_id = touch_id_to_path_[id];
68 SkScalar x = SkIntToScalar(to.x() / kScale);
69 SkScalar y = SkIntToScalar(to.y() / kScale);
70 if (!paths_[path_id].getLastPt(&last) || x != last.x() || y != last.y())
71 paths_[path_id].lineTo(x, y);
72 SchedulePaint();
73 }
74
75 private:
76 // Overridden from views::View.
77 virtual gfx::Size GetPreferredSize() OVERRIDE {
78 return size_;
79 }
80
81 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
82 canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
83 canvas->DrawColor(SkColorSetARGB(25, 0, 0, 0));
84
85 SkPaint paint;
86 paint.setStrokeWidth(SkIntToScalar(2));
87 paint.setStyle(SkPaint::kStroke_Style);
88 for (size_t i = 0; i < arraysize(paths_); ++i) {
89 if (paths_[i].countPoints() == 0)
90 continue;
91 paint.setColor(colors_[i]);
92 if (paths_[i].countPoints() == 1) {
93 SkPoint point = paths_[i].getPoint(0);
94 canvas->sk_canvas()->drawPoint(point.x(), point.y(), paint);
95 } else {
96 canvas->DrawPath(paths_[i], paint);
97 }
98 }
99 }
100
101 TouchObserverHUD* owner_;
102 SkPath paths_[kMaxPaths];
103 SkColor colors_[kMaxPaths];
104
105 int path_index_;
106 int color_index_;
107
108 std::map<int, int> touch_id_to_path_;
109
110 gfx::Size size_;
111
112 DISALLOW_COPY_AND_ASSIGN(TouchHudCanvas);
113 };
114
19 TouchObserverHUD::TouchObserverHUD() { 115 TouchObserverHUD::TouchObserverHUD() {
20 views::View* content = new views::View; 116 views::View* content = new views::View;
21 content->SetLayoutManager(new views::BoxLayout( 117 content->SetLayoutManager(new views::BoxLayout(
22 views::BoxLayout::kVertical, 0, 0, 0)); 118 views::BoxLayout::kVertical, 0, 0, 0));
23 119
120 canvas_ = new TouchHudCanvas(this);
121 content->AddChildView(canvas_);
24 for (int i = 0; i < kMaxTouchPoints; ++i) { 122 for (int i = 0; i < kMaxTouchPoints; ++i) {
25 touch_status_[i] = ui::ET_UNKNOWN; 123 touch_status_[i] = ui::ET_UNKNOWN;
26 touch_labels_[i] = new views::Label; 124 touch_labels_[i] = new views::Label;
27 touch_labels_[i]->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255)); 125 touch_labels_[i]->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255));
28 touch_labels_[i]->SetShadowColors(SK_ColorWHITE, 126 touch_labels_[i]->SetShadowColors(SK_ColorWHITE,
29 SK_ColorWHITE); 127 SK_ColorWHITE);
30 touch_labels_[i]->SetShadowOffset(1, 1); 128 touch_labels_[i]->SetShadowOffset(1, 1);
31 touch_labels_[i]->SetVisible(false); 129 touch_labels_[i]->SetVisible(false);
32 content->AddChildView(touch_labels_[i]); 130 content->AddChildView(touch_labels_[i]);
33 } 131 }
34 132
35 widget_.reset(new views::Widget()); 133 widget_.reset(new views::Widget());
36 views::Widget::InitParams 134 views::Widget::InitParams
37 params(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 135 params(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
38 params.transparent = true; 136 params.transparent = true;
39 params.can_activate = false; 137 params.can_activate = false;
138 params.accept_events = false;
40 params.bounds = gfx::Rect(content->GetPreferredSize()); 139 params.bounds = gfx::Rect(content->GetPreferredSize());
41 params.parent = Shell::GetInstance()->GetContainer( 140 params.parent = Shell::GetInstance()->GetContainer(
42 internal::kShellWindowId_OverlayContainer); 141 internal::kShellWindowId_OverlayContainer);
43 widget_->Init(params); 142 widget_->Init(params);
44 widget_->SetContentsView(content); 143 widget_->SetContentsView(content);
45 widget_->StackAtTop(); 144 widget_->StackAtTop();
46 widget_->Show(); 145 widget_->Show();
47 } 146 }
48 147
49 TouchObserverHUD::~TouchObserverHUD() {} 148 TouchObserverHUD::~TouchObserverHUD() {}
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 185 }
87 186
88 ui::TouchStatus TouchObserverHUD::PreHandleTouchEvent( 187 ui::TouchStatus TouchObserverHUD::PreHandleTouchEvent(
89 aura::Window* target, 188 aura::Window* target,
90 aura::TouchEvent* event) { 189 aura::TouchEvent* event) {
91 if (event->touch_id() >= kMaxTouchPoints) 190 if (event->touch_id() >= kMaxTouchPoints)
92 return ui::TOUCH_STATUS_UNKNOWN; 191 return ui::TOUCH_STATUS_UNKNOWN;
93 192
94 if (event->type() != ui::ET_TOUCH_CANCELLED) 193 if (event->type() != ui::ET_TOUCH_CANCELLED)
95 touch_positions_[event->touch_id()] = event->root_location(); 194 touch_positions_[event->touch_id()] = event->root_location();
195 if (event->type() == ui::ET_TOUCH_PRESSED)
196 canvas_->Start(event->touch_id(), touch_positions_[event->touch_id()]);
197 else
198 canvas_->Update(event->touch_id(), touch_positions_[event->touch_id()]);
96 touch_status_[event->touch_id()] = event->type(); 199 touch_status_[event->touch_id()] = event->type();
97 touch_labels_[event->touch_id()]->SetVisible(true); 200 touch_labels_[event->touch_id()]->SetVisible(true);
98 UpdateTouchPointLabel(event->touch_id()); 201 UpdateTouchPointLabel(event->touch_id());
99 202
100 widget_->SetSize(widget_->GetContentsView()->GetPreferredSize()); 203 widget_->SetSize(widget_->GetContentsView()->GetPreferredSize());
101 204
102 return ui::TOUCH_STATUS_UNKNOWN; 205 return ui::TOUCH_STATUS_UNKNOWN;
103 } 206 }
104 207
105 ui::GestureStatus TouchObserverHUD::PreHandleGestureEvent( 208 ui::GestureStatus TouchObserverHUD::PreHandleGestureEvent(
106 aura::Window* target, 209 aura::Window* target,
107 aura::GestureEvent* event) { 210 aura::GestureEvent* event) {
108 return ui::GESTURE_STATUS_UNKNOWN; 211 return ui::GESTURE_STATUS_UNKNOWN;
109 } 212 }
110 213
111 } // namespace internal 214 } // namespace internal
112 } // namespace ash 215 } // namespace ash
OLDNEW
« no previous file with comments | « ash/touch/touch_observer_hud.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698