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 Slide; 21 22 using SlideFactory = Slide* (*)(); 23 using SlideRegistry = sk_tools::Registry<SlideFactory>; 24 25 #define DEF_SLIDE(code) \ 26 static Slide* SK_MACRO_APPEND_LINE(F_)() { code } \ 27 static SlideRegistry SK_MACRO_APPEND_LINE(R_)(SK_MACRO_APPEND_LINE(F_)); 28 29 class Slide : public SkRefCnt { 30 public: 31 /** 32 * A slide may have a content dimensions that is independent of the current window size. An 33 * empty size indicates that the Slide's dimensions are equal to the window's dimensions. 34 */ getDimensions()35 virtual SkISize getDimensions() const { return SkISize::MakeEmpty(); } 36 gpuTeardown()37 virtual void gpuTeardown() { } 38 virtual void draw(SkCanvas* canvas) = 0; animate(double nanos)39 virtual bool animate(double nanos) { return false; } load(SkScalar winWidth,SkScalar winHeight)40 virtual void load(SkScalar winWidth, SkScalar winHeight) {} resize(SkScalar winWidth,SkScalar winHeight)41 virtual void resize(SkScalar winWidth, SkScalar winHeight) {} unload()42 virtual void unload() {} 43 onChar(SkUnichar c)44 virtual bool onChar(SkUnichar c) { return false; } onMouse(SkScalar x,SkScalar y,skui::InputState state,skui::ModifierKey modifiers)45 virtual bool onMouse(SkScalar x, SkScalar y, skui::InputState state, 46 skui::ModifierKey modifiers) { return false; } 47 onGetControls(SkMetaData *)48 virtual bool onGetControls(SkMetaData*) { return false; } onSetControls(const SkMetaData &)49 virtual void onSetControls(const SkMetaData&) {} 50 getName()51 const SkString& getName() { return fName; } 52 53 protected: 54 SkString fName; 55 }; 56 57 #endif 58