| 1 |
/* |
| 2 |
* Copyright 2016 Google Inc. |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef Slide_DEFINED |
| 9 |
#define Slide_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkRefCnt.h" |
| 12 |
#include "include/core/SkSize.h" |
| 13 |
#include "include/core/SkString.h" |
| 14 |
#include "tools/Registry.h" |
| 15 |
#include "tools/skui/InputState.h" |
| 16 |
#include "tools/skui/ModifierKey.h" |
| 17 |
|
| 18 |
class SkCanvas; |
| 19 |
class SkMetaData; |
| 20 |
class SkSurfaceProps; |
| 21 |
class Slide; |
| 22 |
|
| 23 |
using SlideFactory = Slide* (*)(); |
| 24 |
using SlideRegistry = sk_tools::Registry<SlideFactory>; |
| 25 |
|
| 26 |
#define DEF_SLIDE(code) \ |
| 27 |
static Slide* SK_MACRO_APPEND_LINE(F_)() { code } \ |
| 28 |
static SlideRegistry SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_)); |
| 29 |
|
| 30 |
class Slide : public SkRefCnt { |
| 31 |
public: |
| 32 |
/** |
| 33 |
* A slide may have a content dimensions that is independent of the current window size. An |
| 34 |
* empty size indicates that the Slide's dimensions are equal to the window's dimensions. |
| 35 |
*/ |
| 36 |
virtual SkISize getDimensions() const { return SkISize::MakeEmpty(); } |
| 37 |
|
| 38 |
virtual void gpuTeardown() { } |
| 39 |
virtual void setSurfaceProps(SkSurfaceProps*) {} |
| 40 |
virtual void draw(SkCanvas* canvas) = 0; |
| 41 |
virtual bool animate(double nanos) { return false; } |
| 42 |
virtual void load(SkScalar winWidth, SkScalar winHeight) {} |
| 43 |
virtual void resize(SkScalar winWidth, SkScalar winHeight) {} |
| 44 |
virtual void unload() {} |
| 45 |
|
| 46 |
virtual bool onChar(SkUnichar c) { return false; } |
| 47 |
virtual bool onMouse(SkScalar x, SkScalar y, skui::InputState state, |
| 48 |
skui::ModifierKey modifiers) { return false; } |
| 49 |
|
| 50 |
virtual bool onGetControls(SkMetaData*) { return false; } |
| 51 |
virtual void onSetControls(const SkMetaData&) {} |
| 52 |
|
| 53 |
const SkString& getName() { return fName; } |
| 54 |
|
| 55 |
protected: |
| 56 |
SkString fName; |
| 57 |
}; |
| 58 |
|
| 59 |
#endif |