2016-06-16 16:52:35 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SampleSlide.h"
|
|
|
|
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkCommonFlags.h"
|
2017-11-22 21:36:07 +00:00
|
|
|
#include "SkKey.h"
|
2016-06-16 16:52:35 +00:00
|
|
|
#include "SkOSFile.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
|
2017-11-02 13:46:49 +00:00
|
|
|
using namespace sk_app;
|
|
|
|
|
|
|
|
SampleSlide::SampleSlide(const SkViewFactory* factory)
|
|
|
|
: fViewFactory(factory)
|
|
|
|
, fClick(nullptr) {
|
2016-06-16 16:52:35 +00:00
|
|
|
SkView* view = (*factory)();
|
|
|
|
SampleCode::RequestTitle(view, &fName);
|
|
|
|
view->unref();
|
|
|
|
}
|
|
|
|
|
2017-11-02 13:46:49 +00:00
|
|
|
SampleSlide::~SampleSlide() { delete fClick; }
|
2016-06-16 16:52:35 +00:00
|
|
|
|
|
|
|
void SampleSlide::draw(SkCanvas* canvas) {
|
2017-02-24 20:22:53 +00:00
|
|
|
SkASSERT(fView);
|
2016-06-16 16:52:35 +00:00
|
|
|
fView->draw(canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SampleSlide::load(SkScalar winWidth, SkScalar winHeight) {
|
2017-02-24 20:22:53 +00:00
|
|
|
fView.reset((*fViewFactory)());
|
2016-06-16 16:52:35 +00:00
|
|
|
fView->setVisibleP(true);
|
|
|
|
fView->setClipToBounds(false);
|
|
|
|
fView->setSize(winWidth, winHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SampleSlide::unload() {
|
2017-02-24 20:22:53 +00:00
|
|
|
fView.reset();
|
2016-06-16 16:52:35 +00:00
|
|
|
}
|
|
|
|
|
2017-02-14 20:16:46 +00:00
|
|
|
bool SampleSlide::onChar(SkUnichar c) {
|
2017-02-24 20:22:53 +00:00
|
|
|
if (!fView) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-02-14 20:16:46 +00:00
|
|
|
SkEvent evt(gCharEvtName);
|
|
|
|
evt.setFast32(c);
|
|
|
|
return fView->doQuery(&evt);
|
|
|
|
}
|
|
|
|
|
2017-11-02 13:46:49 +00:00
|
|
|
bool SampleSlide::onMouse(SkScalar x, SkScalar y, Window::InputState state,
|
|
|
|
uint32_t modifiers) {
|
|
|
|
// map to SkView modifiers
|
|
|
|
unsigned modifierKeys = 0;
|
2017-12-04 21:59:36 +00:00
|
|
|
modifierKeys |= (modifiers & Window::kShift_ModifierKey) ? kShift_SkModifierKey : 0;
|
|
|
|
modifierKeys |= (modifiers & Window::kControl_ModifierKey) ? kControl_SkModifierKey : 0;
|
|
|
|
modifierKeys |= (modifiers & Window::kOption_ModifierKey) ? kOption_SkModifierKey : 0;
|
|
|
|
modifierKeys |= (modifiers & Window::kCommand_ModifierKey) ? kCommand_SkModifierKey : 0;
|
2017-11-02 13:46:49 +00:00
|
|
|
|
|
|
|
bool handled = false;
|
|
|
|
switch (state) {
|
|
|
|
case Window::kDown_InputState: {
|
|
|
|
delete fClick;
|
|
|
|
fClick = fView->findClickHandler(SkIntToScalar(x), SkIntToScalar(y), modifierKeys);
|
|
|
|
if (fClick) {
|
|
|
|
SkView::DoClickDown(fClick, x, y, modifierKeys);
|
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Window::kMove_InputState: {
|
|
|
|
if (fClick) {
|
|
|
|
SkView::DoClickMoved(fClick, x, y, modifierKeys);
|
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Window::kUp_InputState: {
|
|
|
|
if (fClick) {
|
|
|
|
SkView::DoClickUp(fClick, x, y, modifierKeys);
|
|
|
|
delete fClick;
|
|
|
|
fClick = nullptr;
|
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return handled;
|
|
|
|
}
|