blob: 68dab9290f3aa9e95cd6fb71c2d1e41cef95ae6f [file] [log] [blame]
jvanverthc7027ab2016-06-16 09:52:35 -07001/*
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#include "SampleSlide.h"
9
10#include "SkCanvas.h"
11#include "SkCommonFlags.h"
12#include "SkOSFile.h"
13#include "SkStream.h"
14
Jim Van Verthc9e7f9c2017-11-02 09:46:49 -040015using namespace sk_app;
16
17SampleSlide::SampleSlide(const SkViewFactory* factory)
18 : fViewFactory(factory)
19 , fClick(nullptr) {
jvanverthc7027ab2016-06-16 09:52:35 -070020 SkView* view = (*factory)();
21 SampleCode::RequestTitle(view, &fName);
22 view->unref();
23}
24
Jim Van Verthc9e7f9c2017-11-02 09:46:49 -040025SampleSlide::~SampleSlide() { delete fClick; }
jvanverthc7027ab2016-06-16 09:52:35 -070026
27void SampleSlide::draw(SkCanvas* canvas) {
Christopher Dalton443ec1b2017-02-24 13:22:53 -070028 SkASSERT(fView);
jvanverthc7027ab2016-06-16 09:52:35 -070029 fView->draw(canvas);
30}
31
32void SampleSlide::load(SkScalar winWidth, SkScalar winHeight) {
Christopher Dalton443ec1b2017-02-24 13:22:53 -070033 fView.reset((*fViewFactory)());
jvanverthc7027ab2016-06-16 09:52:35 -070034 fView->setVisibleP(true);
35 fView->setClipToBounds(false);
36 fView->setSize(winWidth, winHeight);
37}
38
39void SampleSlide::unload() {
Christopher Dalton443ec1b2017-02-24 13:22:53 -070040 fView.reset();
jvanverthc7027ab2016-06-16 09:52:35 -070041}
42
Jim Van Verth6f449692017-02-14 15:16:46 -050043bool SampleSlide::onChar(SkUnichar c) {
Christopher Dalton443ec1b2017-02-24 13:22:53 -070044 if (!fView) {
45 return false;
46 }
Jim Van Verth6f449692017-02-14 15:16:46 -050047 SkEvent evt(gCharEvtName);
48 evt.setFast32(c);
49 return fView->doQuery(&evt);
50}
51
Jim Van Verthc9e7f9c2017-11-02 09:46:49 -040052bool SampleSlide::onMouse(SkScalar x, SkScalar y, Window::InputState state,
53 uint32_t modifiers) {
54 // map to SkView modifiers
55 unsigned modifierKeys = 0;
56 modifierKeys |= (state & Window::kShift_ModifierKey) ? kShift_SkModifierKey : 0;
57 modifierKeys |= (state & Window::kControl_ModifierKey) ? kControl_SkModifierKey : 0;
58 modifierKeys |= (state & Window::kOption_ModifierKey) ? kOption_SkModifierKey : 0;
59 modifierKeys |= (state & Window::kCommand_ModifierKey) ? kCommand_SkModifierKey : 0;
60
61 bool handled = false;
62 switch (state) {
63 case Window::kDown_InputState: {
64 delete fClick;
65 fClick = fView->findClickHandler(SkIntToScalar(x), SkIntToScalar(y), modifierKeys);
66 if (fClick) {
67 SkView::DoClickDown(fClick, x, y, modifierKeys);
68 handled = true;
69 }
70 break;
71 }
72 case Window::kMove_InputState: {
73 if (fClick) {
74 SkView::DoClickMoved(fClick, x, y, modifierKeys);
75 handled = true;
76 }
77 break;
78 }
79 case Window::kUp_InputState: {
80 if (fClick) {
81 SkView::DoClickUp(fClick, x, y, modifierKeys);
82 delete fClick;
83 fClick = nullptr;
84 handled = true;
85 }
86 break;
87 }
88 }
89
90 return handled;
91}
92
jvanverthc7027ab2016-06-16 09:52:35 -070093#if defined(SK_BUILD_FOR_ANDROID)
94// these are normally defined in SkOSWindow_unix, but we don't
95// want to include that
96void SkEvent::SignalNonEmptyQueue() {}
97
98void SkEvent::SignalQueueTimer(SkMSec delay) {}
99#endif