diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-17 17:36:53 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-17 17:36:53 +0000 |
commit | b843d1847fa001e6bead7a077885b18ba47f9fa3 (patch) | |
tree | 5cc221cd81d182231b943b4e511d696e9532b893 | |
parent | b44c414b41f42be1f6256a4d35278b7be5a57230 (diff) | |
download | chromium_src-b843d1847fa001e6bead7a077885b18ba47f9fa3.zip chromium_src-b843d1847fa001e6bead7a077885b18ba47f9fa3.tar.gz chromium_src-b843d1847fa001e6bead7a077885b18ba47f9fa3.tar.bz2 |
ash: Make the touchy heads-up display more colorful/useful.
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10399061
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137680 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/touch/touch_observer_hud.cc | 103 | ||||
-rw-r--r-- | ash/touch/touch_observer_hud.h | 4 |
2 files changed, 107 insertions, 0 deletions
diff --git a/ash/touch/touch_observer_hud.cc b/ash/touch/touch_observer_hud.cc index d383c60..b7773a5 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()); diff --git a/ash/touch/touch_observer_hud.h b/ash/touch/touch_observer_hud.h index 3da6a56..aefa62d 100644 --- a/ash/touch/touch_observer_hud.h +++ b/ash/touch/touch_observer_hud.h @@ -24,6 +24,8 @@ class Widget; namespace ash { namespace internal { +class TouchHudCanvas; + // An event filter which handles system level gesture events. class TouchObserverHUD : public aura::EventFilter { public: @@ -45,7 +47,9 @@ class TouchObserverHUD : public aura::EventFilter { aura::GestureEvent* event) OVERRIDE; static const int kMaxTouchPoints = 32; + scoped_ptr<views::Widget> widget_; + TouchHudCanvas* canvas_; views::Label* touch_labels_[kMaxTouchPoints]; gfx::Point touch_positions_[kMaxTouchPoints]; ui::EventType touch_status_[kMaxTouchPoints]; |