2016-04-06 13:08:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef Window_DEFINED
|
|
|
|
#define Window_DEFINED
|
|
|
|
|
2016-05-06 20:28:57 +00:00
|
|
|
#include "DisplayParams.h"
|
2016-04-21 14:59:44 +00:00
|
|
|
#include "SkRect.h"
|
2016-05-17 19:44:20 +00:00
|
|
|
#include "SkTouchGesture.h"
|
|
|
|
#include "SkTypes.h"
|
2016-05-27 15:52:52 +00:00
|
|
|
#include "SkJSONCPP.h"
|
2016-04-06 19:08:51 +00:00
|
|
|
|
2016-04-06 13:08:59 +00:00
|
|
|
class SkCanvas;
|
|
|
|
|
2016-05-04 20:49:13 +00:00
|
|
|
namespace sk_app {
|
|
|
|
|
2016-05-05 19:32:03 +00:00
|
|
|
class WindowContext;
|
|
|
|
|
2016-04-06 13:08:59 +00:00
|
|
|
class Window {
|
|
|
|
public:
|
|
|
|
static Window* CreateNativeWindow(void* platformData);
|
|
|
|
|
|
|
|
virtual ~Window() {};
|
|
|
|
|
|
|
|
virtual void setTitle(const char*) = 0;
|
|
|
|
virtual void show() = 0;
|
2016-05-27 15:52:52 +00:00
|
|
|
virtual void setUIState(const Json::Value& state) {} // do nothing in default
|
2016-05-23 17:52:34 +00:00
|
|
|
|
|
|
|
// Shedules an invalidation event for window if one is not currently pending.
|
|
|
|
// Make sure that either onPaint or markInvalReceived is called when the client window consumes
|
|
|
|
// the the inval event. They unset fIsContentInvalided which allow future onInval.
|
|
|
|
void inval();
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2016-04-21 14:59:44 +00:00
|
|
|
virtual bool scaleContentToFit() const { return false; }
|
|
|
|
virtual bool supportsContentRect() const { return false; }
|
|
|
|
virtual SkRect getContentRect() { return SkRect::MakeEmpty(); }
|
|
|
|
|
2016-05-20 13:01:06 +00:00
|
|
|
enum BackendType {
|
2016-04-06 13:08:59 +00:00
|
|
|
kNativeGL_BackendType,
|
2016-05-20 13:01:06 +00:00
|
|
|
kVulkan_BackendType,
|
2016-06-07 21:22:37 +00:00
|
|
|
kRaster_BackendType,
|
2016-05-20 13:01:06 +00:00
|
|
|
|
2016-06-07 21:22:37 +00:00
|
|
|
kLast_BackendType = kRaster_BackendType
|
2016-05-20 13:01:06 +00:00
|
|
|
};
|
|
|
|
enum {
|
|
|
|
kBackendTypeCount = kLast_BackendType + 1
|
2016-04-06 13:08:59 +00:00
|
|
|
};
|
|
|
|
|
2016-05-20 13:01:06 +00:00
|
|
|
virtual bool attach(BackendType attachType, const DisplayParams& params) = 0;
|
2016-04-06 13:08:59 +00:00
|
|
|
void detach();
|
|
|
|
|
|
|
|
// input handling
|
2016-05-10 13:50:49 +00:00
|
|
|
enum class Key {
|
|
|
|
kNONE, //corresponds to android's UNKNOWN
|
|
|
|
|
|
|
|
kLeftSoftKey,
|
|
|
|
kRightSoftKey,
|
|
|
|
|
|
|
|
kHome, //!< the home key - added to match android
|
|
|
|
kBack, //!< (CLR)
|
|
|
|
kSend, //!< the green (talk) key
|
|
|
|
kEnd, //!< the red key
|
|
|
|
|
|
|
|
k0,
|
|
|
|
k1,
|
|
|
|
k2,
|
|
|
|
k3,
|
|
|
|
k4,
|
|
|
|
k5,
|
|
|
|
k6,
|
|
|
|
k7,
|
|
|
|
k8,
|
|
|
|
k9,
|
|
|
|
kStar, //!< the * key
|
|
|
|
kHash, //!< the # key
|
|
|
|
|
|
|
|
kUp,
|
|
|
|
kDown,
|
|
|
|
kLeft,
|
|
|
|
kRight,
|
|
|
|
|
|
|
|
kOK, //!< the center key
|
|
|
|
|
|
|
|
kVolUp, //!< volume up - match android
|
|
|
|
kVolDown, //!< volume down - same
|
|
|
|
kPower, //!< power button - same
|
|
|
|
kCamera, //!< camera - same
|
|
|
|
|
|
|
|
kLast = kCamera
|
2016-04-06 19:08:51 +00:00
|
|
|
};
|
2016-05-10 13:50:49 +00:00
|
|
|
static const int kKeyCount = static_cast<int>(Key::kLast) + 1;
|
2016-04-06 19:08:51 +00:00
|
|
|
|
|
|
|
enum ModifierKeys {
|
|
|
|
kShift_ModifierKey = 1 << 0,
|
|
|
|
kControl_ModifierKey = 1 << 1,
|
|
|
|
kOption_ModifierKey = 1 << 2, // same as ALT
|
|
|
|
kCommand_ModifierKey = 1 << 3,
|
|
|
|
kFirstPress_ModifierKey = 1 << 4,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum InputState {
|
|
|
|
kDown_InputState,
|
|
|
|
kUp_InputState,
|
|
|
|
kMove_InputState // only valid for mouse
|
|
|
|
};
|
|
|
|
|
|
|
|
// return value of 'true' means 'I have handled this event'
|
|
|
|
typedef bool(*OnCharFunc)(SkUnichar c, uint32_t modifiers, void* userData);
|
|
|
|
typedef bool(*OnKeyFunc)(Key key, InputState state, uint32_t modifiers, void* userData);
|
|
|
|
typedef bool(*OnMouseFunc)(int x, int y, InputState state, uint32_t modifiers, void* userData);
|
2016-06-06 15:48:47 +00:00
|
|
|
typedef bool(*OnTouchFunc)(intptr_t owner, InputState state, float x, float y, void* userData);
|
2016-05-27 15:52:52 +00:00
|
|
|
typedef void(*OnUIStateChangedFunc)(
|
|
|
|
const SkString& stateName, const SkString& stateValue, void* userData);
|
2016-04-06 13:08:59 +00:00
|
|
|
typedef void(*OnPaintFunc)(SkCanvas*, void* userData);
|
|
|
|
|
2016-04-06 19:08:51 +00:00
|
|
|
void registerCharFunc(OnCharFunc func, void* userData) {
|
|
|
|
fCharFunc = func;
|
|
|
|
fCharUserData = userData;
|
|
|
|
}
|
|
|
|
|
2016-04-06 13:08:59 +00:00
|
|
|
void registerKeyFunc(OnKeyFunc func, void* userData) {
|
|
|
|
fKeyFunc = func;
|
|
|
|
fKeyUserData = userData;
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerMouseFunc(OnMouseFunc func, void* userData) {
|
|
|
|
fMouseFunc = func;
|
|
|
|
fMouseUserData = userData;
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerPaintFunc(OnPaintFunc func, void* userData) {
|
|
|
|
fPaintFunc = func;
|
|
|
|
fPaintUserData = userData;
|
|
|
|
}
|
|
|
|
|
2016-05-17 19:44:20 +00:00
|
|
|
void registerTouchFunc(OnTouchFunc func, void* userData) {
|
|
|
|
fTouchFunc = func;
|
|
|
|
fTouchUserData = userData;
|
|
|
|
}
|
|
|
|
|
2016-05-27 15:52:52 +00:00
|
|
|
void registerUIStateChangedFunc(OnUIStateChangedFunc func, void* userData) {
|
|
|
|
fUIStateChangedFunc = func;
|
|
|
|
fUIStateChangedUserData = userData;
|
|
|
|
}
|
|
|
|
|
2016-04-06 19:08:51 +00:00
|
|
|
bool onChar(SkUnichar c, uint32_t modifiers);
|
|
|
|
bool onKey(Key key, InputState state, uint32_t modifiers);
|
|
|
|
bool onMouse(int x, int y, InputState state, uint32_t modifiers);
|
2016-06-06 15:48:47 +00:00
|
|
|
bool onTouch(intptr_t owner, InputState state, float x, float y); // multi-owner = multi-touch
|
2016-05-27 15:52:52 +00:00
|
|
|
void onUIStateChanged(const SkString& stateName, const SkString& stateValue);
|
2016-04-06 13:08:59 +00:00
|
|
|
void onPaint();
|
2016-04-06 19:08:51 +00:00
|
|
|
void onResize(uint32_t width, uint32_t height);
|
2016-04-06 13:08:59 +00:00
|
|
|
|
2016-04-08 19:51:45 +00:00
|
|
|
uint32_t width() { return fWidth; }
|
|
|
|
uint32_t height() { return fHeight; }
|
|
|
|
|
2016-05-12 16:17:04 +00:00
|
|
|
virtual const DisplayParams& getDisplayParams();
|
2016-05-06 20:28:57 +00:00
|
|
|
void setDisplayParams(const DisplayParams& params);
|
|
|
|
|
2016-04-06 13:08:59 +00:00
|
|
|
protected:
|
|
|
|
Window();
|
|
|
|
|
2016-04-08 19:51:45 +00:00
|
|
|
uint32_t fWidth;
|
|
|
|
uint32_t fHeight;
|
|
|
|
|
2016-04-06 19:08:51 +00:00
|
|
|
OnCharFunc fCharFunc;
|
|
|
|
void* fCharUserData;
|
2016-04-06 13:08:59 +00:00
|
|
|
OnKeyFunc fKeyFunc;
|
|
|
|
void* fKeyUserData;
|
|
|
|
OnMouseFunc fMouseFunc;
|
|
|
|
void* fMouseUserData;
|
2016-05-17 19:44:20 +00:00
|
|
|
OnTouchFunc fTouchFunc;
|
|
|
|
void* fTouchUserData;
|
2016-05-27 15:52:52 +00:00
|
|
|
OnUIStateChangedFunc
|
|
|
|
fUIStateChangedFunc;
|
|
|
|
void* fUIStateChangedUserData;
|
2016-04-06 13:08:59 +00:00
|
|
|
OnPaintFunc fPaintFunc;
|
|
|
|
void* fPaintUserData;
|
|
|
|
|
2016-05-17 19:44:20 +00:00
|
|
|
WindowContext* fWindowContext = nullptr;
|
2016-05-23 17:52:34 +00:00
|
|
|
|
|
|
|
virtual void onInval() = 0;
|
|
|
|
|
|
|
|
// Uncheck fIsContentInvalided to allow future inval/onInval.
|
|
|
|
void markInvalProcessed();
|
|
|
|
|
|
|
|
bool fIsContentInvalidated = false; // use this to avoid duplicate invalidate events
|
2016-04-06 13:08:59 +00:00
|
|
|
};
|
|
|
|
|
2016-05-04 20:49:13 +00:00
|
|
|
} // namespace sk_app
|
2016-04-06 13:08:59 +00:00
|
|
|
#endif
|