skia2/tools/viewer/SampleSlide.cpp
Ben Wagner b2c4ea6219 Move Views into Sample and Viewer.
What is left of the SkView system is used only by samples or viewer.
As a result, move it out of the Skia source tree and re-organize so it
is a bit easier to understand and use more shared code.

Move samplecode/ClockFaceView.cpp to samplecode/SampleTextEffects.cpp,
sice that's what's actually in it.

Move SkAnimTimer.h to tools/timer, since it's actually shared between gm
and samples.

Change-Id: I55dafd94c64e4f930ddbd19168e0f812af86c455
Reviewed-on: https://skia-review.googlesource.com/146161
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
2018-08-09 15:25:32 +00:00

89 lines
2.5 KiB
C++

/*
* 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"
#include "SkOSFile.h"
#include "SkStream.h"
using namespace sk_app;
SampleSlide::SampleSlide(const SampleFactory factory)
: fSampleFactory(factory)
, fClick(nullptr) {
sk_sp<Sample> sample(factory());
Sample::RequestTitle(sample.get(), &fName);
}
SampleSlide::~SampleSlide() { delete fClick; }
void SampleSlide::draw(SkCanvas* canvas) {
SkASSERT(fSample);
fSample->draw(canvas);
}
void SampleSlide::load(SkScalar winWidth, SkScalar winHeight) {
fSample.reset(fSampleFactory());
fSample->setSize(winWidth, winHeight);
}
void SampleSlide::unload() {
fSample.reset();
}
bool SampleSlide::onChar(SkUnichar c) {
if (!fSample) {
return false;
}
Sample::Event evt(Sample::kCharEvtName);
evt.setFast32(c);
return fSample->doQuery(&evt);
}
bool SampleSlide::onMouse(SkScalar x, SkScalar y, Window::InputState state,
uint32_t modifiers) {
// map to Sample::Click modifiers
unsigned modifierKeys = 0;
modifierKeys |= (modifiers & Window::kShift_ModifierKey) ? Sample::Click::kShift_ModifierKey : 0;
modifierKeys |= (modifiers & Window::kControl_ModifierKey) ? Sample::Click::kControl_ModifierKey : 0;
modifierKeys |= (modifiers & Window::kOption_ModifierKey) ? Sample::Click::kOption_ModifierKey : 0;
modifierKeys |= (modifiers & Window::kCommand_ModifierKey) ? Sample::Click::kCommand_ModifierKey : 0;
bool handled = false;
switch (state) {
case Window::kDown_InputState: {
delete fClick;
fClick = fSample->findClickHandler(SkIntToScalar(x), SkIntToScalar(y), modifierKeys);
if (fClick) {
Sample::DoClickDown(fClick, x, y, modifierKeys);
handled = true;
}
break;
}
case Window::kMove_InputState: {
if (fClick) {
Sample::DoClickMoved(fClick, x, y, modifierKeys);
handled = true;
}
break;
}
case Window::kUp_InputState: {
if (fClick) {
Sample::DoClickUp(fClick, x, y, modifierKeys);
delete fClick;
fClick = nullptr;
handled = true;
}
break;
}
}
return handled;
}