Commit b843d184 authored by sadrul@chromium.org's avatar sadrul@chromium.org

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
parent b44c414b
...@@ -7,7 +7,14 @@ ...@@ -7,7 +7,14 @@
#include "ash/shell_window_ids.h" #include "ash/shell_window_ids.h"
#include "base/stringprintf.h" #include "base/stringprintf.h"
#include "base/utf_string_conversions.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/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/background.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
...@@ -16,11 +23,102 @@ ...@@ -16,11 +23,102 @@
namespace ash { namespace ash {
namespace internal { 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() { TouchObserverHUD::TouchObserverHUD() {
views::View* content = new views::View; views::View* content = new views::View;
content->SetLayoutManager(new views::BoxLayout( content->SetLayoutManager(new views::BoxLayout(
views::BoxLayout::kVertical, 0, 0, 0)); views::BoxLayout::kVertical, 0, 0, 0));
canvas_ = new TouchHudCanvas(this);
content->AddChildView(canvas_);
for (int i = 0; i < kMaxTouchPoints; ++i) { for (int i = 0; i < kMaxTouchPoints; ++i) {
touch_status_[i] = ui::ET_UNKNOWN; touch_status_[i] = ui::ET_UNKNOWN;
touch_labels_[i] = new views::Label; touch_labels_[i] = new views::Label;
...@@ -37,6 +135,7 @@ TouchObserverHUD::TouchObserverHUD() { ...@@ -37,6 +135,7 @@ TouchObserverHUD::TouchObserverHUD() {
params(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); params(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
params.transparent = true; params.transparent = true;
params.can_activate = false; params.can_activate = false;
params.accept_events = false;
params.bounds = gfx::Rect(content->GetPreferredSize()); params.bounds = gfx::Rect(content->GetPreferredSize());
params.parent = Shell::GetInstance()->GetContainer( params.parent = Shell::GetInstance()->GetContainer(
internal::kShellWindowId_OverlayContainer); internal::kShellWindowId_OverlayContainer);
...@@ -93,6 +192,10 @@ ui::TouchStatus TouchObserverHUD::PreHandleTouchEvent( ...@@ -93,6 +192,10 @@ ui::TouchStatus TouchObserverHUD::PreHandleTouchEvent(
if (event->type() != ui::ET_TOUCH_CANCELLED) if (event->type() != ui::ET_TOUCH_CANCELLED)
touch_positions_[event->touch_id()] = event->root_location(); 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_status_[event->touch_id()] = event->type();
touch_labels_[event->touch_id()]->SetVisible(true); touch_labels_[event->touch_id()]->SetVisible(true);
UpdateTouchPointLabel(event->touch_id()); UpdateTouchPointLabel(event->touch_id());
......
...@@ -24,6 +24,8 @@ class Widget; ...@@ -24,6 +24,8 @@ class Widget;
namespace ash { namespace ash {
namespace internal { namespace internal {
class TouchHudCanvas;
// An event filter which handles system level gesture events. // An event filter which handles system level gesture events.
class TouchObserverHUD : public aura::EventFilter { class TouchObserverHUD : public aura::EventFilter {
public: public:
...@@ -45,7 +47,9 @@ class TouchObserverHUD : public aura::EventFilter { ...@@ -45,7 +47,9 @@ class TouchObserverHUD : public aura::EventFilter {
aura::GestureEvent* event) OVERRIDE; aura::GestureEvent* event) OVERRIDE;
static const int kMaxTouchPoints = 32; static const int kMaxTouchPoints = 32;
scoped_ptr<views::Widget> widget_; scoped_ptr<views::Widget> widget_;
TouchHudCanvas* canvas_;
views::Label* touch_labels_[kMaxTouchPoints]; views::Label* touch_labels_[kMaxTouchPoints];
gfx::Point touch_positions_[kMaxTouchPoints]; gfx::Point touch_positions_[kMaxTouchPoints];
ui::EventType touch_status_[kMaxTouchPoints]; ui::EventType touch_status_[kMaxTouchPoints];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment