skia2/tools/viewer/SampleSlide.cpp
Mike Klein c0bd9f9fe5 rewrite includes to not need so much -Ifoo
Current strategy: everything from the top

Things to look at first are the manual changes:

   - added tools/rewrite_includes.py
   - removed -Idirectives from BUILD.gn
   - various compile.sh simplifications
   - tweak tools/embed_resources.py
   - update gn/find_headers.py to write paths from the top
   - update gn/gn_to_bp.py SkUserConfig.h layout
     so that #include "include/config/SkUserConfig.h" always
     gets the header we want.

No-Presubmit: true
Change-Id: I73a4b181654e0e38d229bc456c0d0854bae3363e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209706
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Hal Canary <halcanary@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
2019-04-24 16:27:11 +00:00

92 lines
2.6 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 "tools/viewer/SampleSlide.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkStream.h"
#include "src/core/SkOSFile.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; }
SkISize SampleSlide::getDimensions() const {
return SkISize::Make(SkScalarCeilToInt(fSample->width()), SkScalarCeilToInt(fSample->height()));
}
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;
}