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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/touch/touch_observer_hud.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/touch/touch_observer_hud.cc
diff --git a/ash/touch/touch_observer_hud.cc b/ash/touch/touch_observer_hud.cc
index d383c60343835f7f3912dd56b65cb44731545715..b7773a5acd390acf7426c8e7ca5f19f0ff840327 100644
--- a/ash/touch/touch_observer_hud.cc
+++ b/ash/touch/touch_observer_hud.cc
@@ -7,7 +7,14 @@
#include "ash/shell_window_ids.h"
#include "base/stringprintf.h"
#include "base/utf_string_conversions.h"
+#include "third_party/skia/include/core/SkPath.h"
+#include "third_party/skia/include/core/SkXfermode.h"
#include "ui/aura/event.h"
+#include "ui/gfx/canvas.h"
+#include "ui/gfx/monitor.h"
+#include "ui/gfx/rect.h"
+#include "ui/gfx/screen.h"
+#include "ui/gfx/size.h"
#include "ui/views/background.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
@@ -16,11 +23,102 @@
namespace ash {
namespace internal {
+const int kMaxPaths = 15;
+const int kScale = 10;
+const int kColors[] = {
+ SK_ColorYELLOW,
+ SK_ColorGREEN,
+ SK_ColorRED,
+ SK_ColorBLUE,
+ SK_ColorMAGENTA,
+ SK_ColorCYAN,
+ SK_ColorWHITE,
+ SK_ColorBLACK
+};
+
+class TouchHudCanvas : public views::View {
+ public:
+ explicit TouchHudCanvas(TouchObserverHUD* owner)
+ : owner_(owner),
+ path_index_(0),
+ color_index_(0) {
+ gfx::Monitor monitor = gfx::Screen::GetPrimaryMonitor();
+ gfx::Rect bounds = monitor.bounds();
+ size_.set_width(bounds.width() / kScale);
+ size_.set_height(bounds.height() / kScale);
+ }
+
+ virtual ~TouchHudCanvas() {}
+
+ void Start(int id, const gfx::Point& point) {
+ paths_[path_index_].reset();
+ paths_[path_index_].moveTo(SkIntToScalar(point.x() / kScale),
+ SkIntToScalar(point.y() / kScale));
+ colors_[path_index_] = kColors[color_index_];
+ color_index_ = (color_index_ + 1) % arraysize(kColors);
+
+ touch_id_to_path_[id] = path_index_;
+ path_index_ = (path_index_ + 1) % kMaxPaths;
+ SchedulePaint();
+ }
+
+ void Update(int id, gfx::Point& to) {
+ SkPoint last;
+ int path_id = touch_id_to_path_[id];
+ SkScalar x = SkIntToScalar(to.x() / kScale);
+ SkScalar y = SkIntToScalar(to.y() / kScale);
+ if (!paths_[path_id].getLastPt(&last) || x != last.x() || y != last.y())
+ paths_[path_id].lineTo(x, y);
+ SchedulePaint();
+ }
+
+ private:
+ // Overridden from views::View.
+ virtual gfx::Size GetPreferredSize() OVERRIDE {
+ return size_;
+ }
+
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
+ canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
+ canvas->DrawColor(SkColorSetARGB(25, 0, 0, 0));
+
+ SkPaint paint;
+ paint.setStrokeWidth(SkIntToScalar(2));
+ paint.setStyle(SkPaint::kStroke_Style);
+ for (size_t i = 0; i < arraysize(paths_); ++i) {
+ if (paths_[i].countPoints() == 0)
+ continue;
+ paint.setColor(colors_[i]);
+ if (paths_[i].countPoints() == 1) {
+ SkPoint point = paths_[i].getPoint(0);
+ canvas->sk_canvas()->drawPoint(point.x(), point.y(), paint);
+ } else {
+ canvas->DrawPath(paths_[i], paint);
+ }
+ }
+ }
+
+ TouchObserverHUD* owner_;
+ SkPath paths_[kMaxPaths];
+ SkColor colors_[kMaxPaths];
+
+ int path_index_;
+ int color_index_;
+
+ std::map<int, int> touch_id_to_path_;
+
+ gfx::Size size_;
+
+ DISALLOW_COPY_AND_ASSIGN(TouchHudCanvas);
+};
+
TouchObserverHUD::TouchObserverHUD() {
views::View* content = new views::View;
content->SetLayoutManager(new views::BoxLayout(
views::BoxLayout::kVertical, 0, 0, 0));
+ canvas_ = new TouchHudCanvas(this);
+ content->AddChildView(canvas_);
for (int i = 0; i < kMaxTouchPoints; ++i) {
touch_status_[i] = ui::ET_UNKNOWN;
touch_labels_[i] = new views::Label;
@@ -37,6 +135,7 @@ TouchObserverHUD::TouchObserverHUD() {
params(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.transparent = true;
params.can_activate = false;
+ params.accept_events = false;
params.bounds = gfx::Rect(content->GetPreferredSize());
params.parent = Shell::GetInstance()->GetContainer(
internal::kShellWindowId_OverlayContainer);
@@ -93,6 +192,10 @@ ui::TouchStatus TouchObserverHUD::PreHandleTouchEvent(
if (event->type() != ui::ET_TOUCH_CANCELLED)
touch_positions_[event->touch_id()] = event->root_location();
+ if (event->type() == ui::ET_TOUCH_PRESSED)
+ canvas_->Start(event->touch_id(), touch_positions_[event->touch_id()]);
+ else
+ canvas_->Update(event->touch_id(), touch_positions_[event->touch_id()]);
touch_status_[event->touch_id()] = event->type();
touch_labels_[event->touch_id()]->SetVisible(true);
UpdateTouchPointLabel(event->touch_id());
« 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