tools/skui: put all enums in a common namespace

Change-Id: Icd331e8946d80652750b8b6ea0db65f5f676ac3e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/238058
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
This commit is contained in:
Hal Canary 2019-08-29 10:39:22 -04:00 committed by Skia Commit-Bot
parent ca8b07cf8a
commit b1f411ac05
52 changed files with 489 additions and 475 deletions

View File

@ -109,7 +109,7 @@ void HelloWorld::onIdle() {
fWindow->inval();
}
bool HelloWorld::onChar(SkUnichar c, ModifierKey modifiers) {
bool HelloWorld::onChar(SkUnichar c, skui::ModifierKey modifiers) {
if (' ' == c) {
fBackendType = Window::kRaster_BackendType == fBackendType ? Window::kNativeGL_BackendType
: Window::kRaster_BackendType;

View File

@ -22,7 +22,7 @@ public:
void onBackendCreated() override;
void onPaint(SkSurface*) override;
bool onChar(SkUnichar c, ModifierKey modifiers) override;
bool onChar(SkUnichar c, skui::ModifierKey modifiers) override;
private:
void updateTitle();

View File

@ -7,35 +7,41 @@
#ifndef SkEnumOperators_DEFINED
#define SkEnumOperators_DEFINED
#include "include/private/SkTLogic.h"
#include <type_traits>
namespace skstd {
template <typename T> struct is_bitmask_enum : std::false_type {};
template <typename E> SK_WHEN(skstd::is_bitmask_enum<E>::value, bool) constexpr Any(E e) {
template <typename E>
typename std::enable_if<skstd::is_bitmask_enum<E>::value, bool>::type constexpr Any(E e) {
return static_cast<typename std::underlying_type<E>::type>(e) != 0;
}
}
} // namespace skstd
template <typename E> SK_WHEN(skstd::is_bitmask_enum<E>::value, E) constexpr operator|(E l, E r) {
template <typename E>
typename std::enable_if<skstd::is_bitmask_enum<E>::value, E>::type constexpr operator|(E l, E r) {
using U = typename std::underlying_type<E>::type;
return static_cast<E>(static_cast<U>(l) | static_cast<U>(r));
}
template <typename E> SK_WHEN(skstd::is_bitmask_enum<E>::value, E&) constexpr operator|=(E& l, E r) {
template <typename E>
typename std::enable_if<skstd::is_bitmask_enum<E>::value, E&>::type constexpr operator|=(E& l, E r) {
return l = l | r;
}
template <typename E> SK_WHEN(skstd::is_bitmask_enum<E>::value, E) constexpr operator&(E l, E r) {
template <typename E>
typename std::enable_if<skstd::is_bitmask_enum<E>::value, E>::type constexpr operator&(E l, E r) {
using U = typename std::underlying_type<E>::type;
return static_cast<E>(static_cast<U>(l) & static_cast<U>(r));
}
template <typename E> SK_WHEN(skstd::is_bitmask_enum<E>::value, E&) constexpr operator&=(E& l, E r) {
template <typename E>
typename std::enable_if<skstd::is_bitmask_enum<E>::value, E&>::type constexpr operator&=(E& l, E r) {
return l = l & r;
}
template <typename E> SK_WHEN(skstd::is_bitmask_enum<E>::value, E) constexpr operator~(E e) {
template <typename E>
typename std::enable_if<skstd::is_bitmask_enum<E>::value, E>::type constexpr operator~(E e) {
return static_cast<E>(~static_cast<typename std::underlying_type<E>::type>(e));
}

View File

@ -8,9 +8,9 @@
#include "include/core/SkSurface.h"
#include "include/core/SkTime.h"
#include "tools/ModifierKey.h"
#include "tools/sk_app/Application.h"
#include "tools/sk_app/Window.h"
#include "tools/skui/ModifierKey.h"
#include "modules/skplaintexteditor/include/editor.h"
@ -23,9 +23,9 @@ using SkPlainTextEditor::Editor;
using SkPlainTextEditor::StringView;
#ifdef SK_EDITOR_DEBUG_OUT
static const char* key_name(sk_app::Window::Key k) {
static const char* key_name(skui::Key k) {
switch (k) {
#define M(X) case sk_app::Window::Key::k ## X: return #X
#define M(X) case skui::Key::k ## X: return #X
M(NONE); M(LeftSoftKey); M(RightSoftKey); M(Home); M(Back); M(Send); M(End); M(0); M(1);
M(2); M(3); M(4); M(5); M(6); M(7); M(8); M(9); M(Star); M(Hash); M(Up); M(Down); M(Left);
M(Right); M(Tab); M(PageUp); M(PageDown); M(Delete); M(Escape); M(Shift); M(Ctrl);
@ -36,15 +36,15 @@ static const char* key_name(sk_app::Window::Key k) {
}
}
static SkString modifiers_desc(ModifierKey m) {
static SkString modifiers_desc(skui::ModifierKey m) {
SkString s;
#define M(X) if (m & ModifierKey::k ## X ##) { s.append(" {" #X "}"); }
#define M(X) if (m & skui::ModifierKey::k ## X ##) { s.append(" {" #X "}"); }
M(Shift) M(Control) M(Option) M(Command) M(FirstPress)
#undef M
return s;
}
static void debug_on_char(SkUnichar c, ModifierKey modifiers) {
static void debug_on_char(SkUnichar c, skui::ModifierKey modifiers) {
SkString m = modifiers_desc(modifiers);
if ((unsigned)c < 0x100) {
SkDebugf("char: %c (0x%02X)%s\n", (char)(c & 0xFF), (unsigned)c, m.c_str());
@ -53,19 +53,19 @@ static void debug_on_char(SkUnichar c, ModifierKey modifiers) {
}
}
static void debug_on_key(sk_app::Window::Key key, InputState, ModifierKey modi) {
static void debug_on_key(skui::Key key, skui::InputState, skui::ModifierKey modi) {
SkDebugf("key: %s%s\n", key_name(key), modifiers_desc(modi).c_str());
}
#endif // SK_EDITOR_DEBUG_OUT
static Editor::Movement convert(sk_app::Window::Key key) {
static Editor::Movement convert(skui::Key key) {
switch (key) {
case sk_app::Window::Key::kLeft: return Editor::Movement::kLeft;
case sk_app::Window::Key::kRight: return Editor::Movement::kRight;
case sk_app::Window::Key::kUp: return Editor::Movement::kUp;
case sk_app::Window::Key::kDown: return Editor::Movement::kDown;
case sk_app::Window::Key::kHome: return Editor::Movement::kHome;
case sk_app::Window::Key::kEnd: return Editor::Movement::kEnd;
case skui::Key::kLeft: return Editor::Movement::kLeft;
case skui::Key::kRight: return Editor::Movement::kRight;
case skui::Key::kUp: return Editor::Movement::kUp;
case skui::Key::kDown: return Editor::Movement::kDown;
case skui::Key::kHome: return Editor::Movement::kHome;
case skui::Key::kEnd: return Editor::Movement::kEnd;
default: return Editor::Movement::kNowhere;
}
}
@ -169,31 +169,31 @@ struct EditorLayer : public sk_app::Window::Layer {
void inval() { if (fParent) { fParent->inval(); } }
bool onMouseWheel(float delta, ModifierKey) override {
bool onMouseWheel(float delta, skui::ModifierKey) override {
this->scroll(-(int)(delta * fEditor.font().getSpacing()));
return true;
}
bool onMouse(int x, int y, InputState state, ModifierKey modifiers) override {
bool mouseDown = InputState::kDown == state;
bool onMouse(int x, int y, skui::InputState state, skui::ModifierKey modifiers) override {
bool mouseDown = skui::InputState::kDown == state;
if (mouseDown) {
fMouseDown = true;
} else if (InputState::kUp == state) {
} else if (skui::InputState::kUp == state) {
fMouseDown = false;
}
bool shiftOrDrag = skstd::Any(modifiers & ModifierKey::kShift) || !mouseDown;
bool shiftOrDrag = skstd::Any(modifiers & skui::ModifierKey::kShift) || !mouseDown;
if (fMouseDown) {
return this->move(fEditor.getPosition({x - fMargin, y + fPos - fMargin}), shiftOrDrag);
}
return false;
}
bool onChar(SkUnichar c, ModifierKey modi) override {
bool onChar(SkUnichar c, skui::ModifierKey modi) override {
using skstd::Any;
modi &= ~ModifierKey::kFirstPress;
if (!Any(modi & (ModifierKey::kControl |
ModifierKey::kOption |
ModifierKey::kCommand))) {
modi &= ~skui::ModifierKey::kFirstPress;
if (!Any(modi & (skui::ModifierKey::kControl |
skui::ModifierKey::kOption |
skui::ModifierKey::kCommand))) {
if (((unsigned)c < 0x7F && (unsigned)c >= 0x20) || c == '\n') {
char ch = (char)c;
fEditor.insert(fTextPos, &ch, 1);
@ -203,8 +203,8 @@ struct EditorLayer : public sk_app::Window::Layer {
return this->moveCursor(Editor::Movement::kRight);
}
}
static constexpr ModifierKey kCommandOrControl = ModifierKey::kCommand |
ModifierKey::kControl;
static constexpr skui::ModifierKey kCommandOrControl = skui::ModifierKey::kCommand |
skui::ModifierKey::kControl;
if (Any(modi & kCommandOrControl) && !Any(modi & ~kCommandOrControl)) {
switch (c) {
case 'p':
@ -299,33 +299,33 @@ struct EditorLayer : public sk_app::Window::Layer {
return true;
}
bool onKey(sk_app::Window::Key key,
InputState state,
ModifierKey modifiers) override {
if (state != InputState::kDown) {
bool onKey(skui::Key key,
skui::InputState state,
skui::ModifierKey modifiers) override {
if (state != skui::InputState::kDown) {
return false; // ignore keyup
}
// ignore other modifiers.
using skstd::Any;
ModifierKey ctrlAltCmd = modifiers & (ModifierKey::kControl |
ModifierKey::kOption |
ModifierKey::kCommand);
bool shift = Any(modifiers & (ModifierKey::kShift));
skui::ModifierKey ctrlAltCmd = modifiers & (skui::ModifierKey::kControl |
skui::ModifierKey::kOption |
skui::ModifierKey::kCommand);
bool shift = Any(modifiers & (skui::ModifierKey::kShift));
if (!Any(ctrlAltCmd)) {
// no modifiers
switch (key) {
case sk_app::Window::Key::kPageDown:
case skui::Key::kPageDown:
return this->scroll(fHeight * 4 / 5);
case sk_app::Window::Key::kPageUp:
case skui::Key::kPageUp:
return this->scroll(-fHeight * 4 / 5);
case sk_app::Window::Key::kLeft:
case sk_app::Window::Key::kRight:
case sk_app::Window::Key::kUp:
case sk_app::Window::Key::kDown:
case sk_app::Window::Key::kHome:
case sk_app::Window::Key::kEnd:
case skui::Key::kLeft:
case skui::Key::kRight:
case skui::Key::kUp:
case skui::Key::kDown:
case skui::Key::kHome:
case skui::Key::kEnd:
return this->moveCursor(convert(key), shift);
case sk_app::Window::Key::kDelete:
case skui::Key::kDelete:
if (fMarkPos != Editor::TextPosition()) {
(void)this->move(fEditor.remove(fMarkPos, fTextPos), false);
} else {
@ -334,7 +334,7 @@ struct EditorLayer : public sk_app::Window::Layer {
}
this->inval();
return true;
case sk_app::Window::Key::kBack:
case skui::Key::kBack:
if (fMarkPos != Editor::TextPosition()) {
(void)this->move(fEditor.remove(fMarkPos, fTextPos), false);
} else {
@ -343,16 +343,16 @@ struct EditorLayer : public sk_app::Window::Layer {
}
this->inval();
return true;
case sk_app::Window::Key::kOK:
case skui::Key::kOK:
return this->onChar('\n', modifiers);
default:
break;
}
} else if (skstd::Any(ctrlAltCmd & (ModifierKey::kControl | ModifierKey::kCommand))) {
} else if (skstd::Any(ctrlAltCmd & (skui::ModifierKey::kControl | skui::ModifierKey::kCommand))) {
switch (key) {
case sk_app::Window::Key::kLeft:
case skui::Key::kLeft:
return this->moveCursor(Editor::Movement::kWordLeft, shift);
case sk_app::Window::Key::kRight:
case skui::Key::kRight:
return this->moveCursor(Editor::Movement::kWordRight, shift);
default:
break;

View File

@ -10,7 +10,7 @@
#include "include/effects/SkPerlinNoiseShader.h"
#include "samplecode/Sample.h"
#include "src/utils/SkPatchUtils.h"
#include "tools/ModifierKey.h"
#include "tools/skui/ModifierKey.h"
static void draw_control_points(SkCanvas* canvas, const SkPoint cubics[12]) {
//draw control points
@ -167,12 +167,12 @@ protected:
return SkPoint::Length(pt.fX - x, pt.fY - y) < SkIntToScalar(5);
}
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey modi) override {
modi &= ~ModifierKey::kFirstPress; // ignore this
if (ModifierKey::kShift == modi) {
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
modi &= ~skui::ModifierKey::kFirstPress; // ignore this
if (skui::ModifierKey::kShift == modi) {
return new PtClick(-1);
}
if (ModifierKey::kControl == modi) {
if (skui::ModifierKey::kControl == modi) {
return new PtClick(-2);
}
SkPoint clickPoint = {x, y};

View File

@ -61,9 +61,9 @@ void Sample::draw(SkCanvas* canvas) {
////////////////////////////////////////////////////////////////////////////
bool Sample::mouse(SkPoint point, InputState clickState, ModifierKey modifierKeys) {
bool Sample::mouse(SkPoint point, skui::InputState clickState, skui::ModifierKey modifierKeys) {
switch (clickState) {
case InputState::kDown:
case skui::InputState::kDown:
fClick = nullptr;
if (point.x() < 0 || point.y() < 0 || point.x() >= fWidth || point.y() >= fHeight) {
return false;
@ -73,24 +73,24 @@ bool Sample::mouse(SkPoint point, InputState clickState, ModifierKey modifierKey
return false;
}
fClick->fPrev = fClick->fCurr = fClick->fOrig = point;
fClick->fState = InputState::kDown;
fClick->fState = skui::InputState::kDown;
fClick->fModifierKeys = modifierKeys;
this->onClick(fClick.get());
return true;
case InputState::kMove:
case skui::InputState::kMove:
if (fClick) {
fClick->fPrev = fClick->fCurr;
fClick->fCurr = point;
fClick->fState = InputState::kMove;
fClick->fState = skui::InputState::kMove;
fClick->fModifierKeys = modifierKeys;
return this->onClick(fClick.get());
}
return false;
case InputState::kUp:
case skui::InputState::kUp:
if (fClick) {
fClick->fPrev = fClick->fCurr;
fClick->fCurr = point;
fClick->fState = InputState::kUp;
fClick->fState = skui::InputState::kUp;
fClick->fModifierKeys = modifierKeys;
bool result = this->onClick(fClick.get());
fClick = nullptr;
@ -106,7 +106,7 @@ bool Sample::mouse(SkPoint point, InputState clickState, ModifierKey modifierKey
void Sample::onSizeChange() {}
Sample::Click* Sample::onFindClickHandler(SkScalar x, SkScalar y, ModifierKey modi) {
Sample::Click* Sample::onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) {
return nullptr;
}

View File

@ -13,10 +13,10 @@
#include "include/core/SkRefCnt.h"
#include "include/core/SkString.h"
#include "include/private/SkMacros.h"
#include "tools/InputState.h"
#include "tools/ModifierKey.h"
#include "tools/Registry.h"
#include "tools/SkMetaData.h"
#include "tools/skui/InputState.h"
#include "tools/skui/ModifierKey.h"
class SkCanvas;
class Sample;
@ -59,11 +59,11 @@ public:
SkPoint fOrig = {0, 0};
SkPoint fPrev = {0, 0};
SkPoint fCurr = {0, 0};
InputState fState = InputState::kDown;
ModifierKey fModifierKeys = ModifierKey::kNone;
skui::InputState fState = skui::InputState::kDown;
skui::ModifierKey fModifierKeys = skui::ModifierKey::kNone;
SkMetaData fMeta;
};
bool mouse(SkPoint point, InputState clickState, ModifierKey modifierKeys);
bool mouse(SkPoint point, skui::InputState clickState, skui::ModifierKey modifierKeys);
void setBGColor(SkColor color) { fBGColor = color; }
bool animate(double nanos) { return this->onAnimate(nanos); }
@ -75,7 +75,7 @@ protected:
virtual void onSizeChange();
/** Override this if you might handle the click */
virtual Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey modi);
virtual Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi);
/** Override to track clicks. Return true as long as you want to track the pen/mouse. */
virtual bool onClick(Click*);

View File

@ -889,8 +889,8 @@ public:
return true;
}
void savePath(InputState state) {
if (state != InputState::kDown) {
void savePath(skui::InputState state) {
if (state != skui::InputState::kDown) {
return;
}
if (fUndo && fUndo->fPath == fPath) {
@ -1604,7 +1604,7 @@ public:
return -1;
}
virtual Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey modi) override {
virtual Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
SkPoint pt = {x, y};
int ptHit = hittest_pt(pt);
if (ptHit >= 0) {
@ -1679,7 +1679,7 @@ public:
fWeightControl.fVisible = myClick->fVerb == SkPath::kConic_Verb;
} break;
case MyClick::kControlType: {
if (click->fState != InputState::kDown && myClick->isButton()) {
if (click->fState != skui::InputState::kDown && myClick->isButton()) {
return true;
}
switch (myClick->fControl) {
@ -1819,7 +1819,7 @@ bool AAGeometryView::onChar(SkUnichar uni) {
Button* button = kButtonList[index].fButton;
if (button->fVisible && uni == button->fLabel) {
MyClick click(MyClick::kControlType, kButtonList[index].fButtonType);
click.fState = InputState::kDown;
click.fState = skui::InputState::kDown;
(void) this->onClick(&click);
return true;
}
@ -1835,7 +1835,7 @@ bool AAGeometryView::onChar(SkUnichar uni) {
Button* button = kButtonList[index].fButton;
if (button->fVisible && (uni & ~0x20) == (button->fLabel & ~0x20)) {
MyClick click(MyClick::kControlType, kButtonList[index].fButtonType);
click.fState = InputState::kDown;
click.fState = skui::InputState::kDown;
(void) this->onClick(&click);
return true;
}

View File

@ -47,7 +47,7 @@ class CCPRGeometryView : public Sample {
void onOnceBeforeDraw() override { this->updateGpuData(); }
void onDrawContent(SkCanvas*) override;
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey) override;
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override;
bool onClick(Sample::Click*) override;
bool onChar(SkUnichar) override;
SkString name() override { return SkString("CCPRGeometry"); }
@ -417,7 +417,7 @@ private:
int fPtIdx;
};
Sample::Click* CCPRGeometryView::onFindClickHandler(SkScalar x, SkScalar y, ModifierKey) {
Sample::Click* CCPRGeometryView::onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) {
for (int i = 0; i < 4; ++i) {
if (PrimitiveType::kCubics != fPrimitiveType && 2 == i) {
continue;

View File

@ -380,7 +380,7 @@ public:
}
}
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey) override;
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override;
bool onClick(Sample::Click*) override;
bool onChar(SkUnichar) override;
SkString name() override { return SkString("DegenerateQuad"); }
@ -478,7 +478,7 @@ private:
}
};
Sample::Click* DegenerateQuadSample::onFindClickHandler(SkScalar x, SkScalar y, ModifierKey) {
Sample::Click* DegenerateQuadSample::onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) {
SkPoint inCTM = SkPoint::Make((x - kViewOffset) / kViewScale, (y - kViewOffset) / kViewScale);
for (int i = 0; i < 4; ++i) {
if ((fCorners[i] - inCTM).length() < 10.f / kViewScale) {

View File

@ -468,7 +468,7 @@ protected:
}
}
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey modi) override {
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
SkPoint pt = { x, y };
int index = -1;
int count = fFB.getTriangle() ? 3 : 2;

View File

@ -156,7 +156,7 @@ protected:
return true;
}
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey modi) override {
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
// search backwards to find the top-most
for (int i = N - 1; i >= 0; --i) {
if (fArray[i].fDrawable->hitTest(x, y)) {

View File

@ -216,7 +216,7 @@ protected:
return true;
}
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey modi) override {
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
fDoAA = !fDoAA;
return this->INHERITED::onFindClickHandler(x, y, modi);
}

View File

@ -217,7 +217,7 @@ protected:
return true;
}
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey modi) override {
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
return new Click();
}

View File

@ -67,7 +67,7 @@ protected:
canvas->drawRect(fRect, paint);
}
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey modi) override {
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
return this->INHERITED::onFindClickHandler(x, y, modi);
}

View File

@ -109,7 +109,7 @@ protected:
}
virtual Sample::Click* onFindClickHandler(SkScalar x, SkScalar y,
ModifierKey modi) override {
skui::ModifierKey modi) override {
lua_State* L = this->ensureLua();
lua_getglobal(L, gClickName);
if (lua_isfunction(L, -1)) {
@ -130,10 +130,10 @@ protected:
bool onClick(Click* click) override {
const char* state = nullptr;
switch (click->fState) {
case InputState::kMove:
case skui::InputState::kMove:
state = "moved";
break;
case InputState::kUp:
case skui::InputState::kUp:
state = "up";
break;
default:

View File

@ -71,7 +71,7 @@ protected:
}
}
virtual Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey) override {
virtual Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override {
return fRect.contains(SkScalarRoundToInt(x),
SkScalarRoundToInt(y)) ? new Click() : nullptr;
}
@ -154,7 +154,7 @@ protected:
canvas->restore();
}
virtual Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey) override {
virtual Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override {
fMode = (fMode == SkBlendMode::kSrcOver) ? SkBlendMode::kClear : SkBlendMode::kSrcOver;
return fRect.contains(SkScalarRoundToInt(x),
SkScalarRoundToInt(y)) ? new Click() : nullptr;

View File

@ -297,7 +297,7 @@ struct PatchView : public Sample {
return SkPoint::Length(pt.fX - x, pt.fY - y) < SkIntToScalar(5);
}
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey modi) override {
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
x -= DX;
y -= DY;
for (size_t i = 0; i < SK_ARRAY_COUNT(fPts); i++) {
@ -396,7 +396,7 @@ protected:
// canvas->drawPath(fPath, fSkeletonP);
}
Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey modi) override {
Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
Click* click = new Click();
fPath.reset();
fPath.moveTo(x, y);
@ -405,7 +405,7 @@ protected:
bool onClick(Click* click) override {
switch (click->fState) {
case InputState::kMove:
case skui::InputState::kMove:
fPath.lineTo(click->fCurr);
fDirty = true;
break;
@ -484,7 +484,7 @@ protected:
this->dodraw(canvas, nullptr, 600, 0, &p);
}
Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey modi) override {
Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
Click* click = new Click();
fPath.reset();
fPath.moveTo(x, y);
@ -493,7 +493,7 @@ protected:
bool onClick(Click* click) override {
switch (click->fState) {
case InputState::kMove:
case skui::InputState::kMove:
fPath.lineTo(click->fCurr);
break;
default:

View File

@ -189,7 +189,7 @@ protected:
return true;
}
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey modi) override {
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
fShowHairline = !fShowHairline;
return nullptr;
}
@ -289,7 +289,7 @@ protected:
return false;
}
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey modi) override {
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
const SkScalar tol = 4;
const SkRect r = SkRect::MakeXYWH(x - tol, y - tol, tol * 2, tol * 2);
for (int i = 0; i < N; ++i) {
@ -417,7 +417,7 @@ protected:
return false;
}
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey modi) override {
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
const SkScalar tol = 4;
const SkRect r = SkRect::MakeXYWH(x - tol, y - tol, tol * 2, tol * 2);
for (int i = 0; i < N; ++i) {
@ -534,7 +534,7 @@ protected:
return false;
}
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey modi) override {
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
const SkScalar tol = 8;
const SkRect r = SkRect::MakeXYWH(x - tol, y - tol, tol * 2, tol * 2);
for (int i = 0; i < N; ++i) {
@ -730,7 +730,7 @@ protected:
return false;
}
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey modi) override {
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
const SkScalar tol = 8;
const SkRect r = SkRect::MakeXYWH(x - tol, y - tol, tol * 2, tol * 2);
for (int i = 0; i < N; ++i) {

View File

@ -52,7 +52,7 @@ protected:
canvas->drawOval(oval, p);
}
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey) override {
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override {
return new Click();
}
@ -277,7 +277,7 @@ protected:
return dx*dx + dy*dy <= rad*rad;
}
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey) override {
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override {
for (int i = 0; i < N; ++i) {
if (hit_test(fPoly[i], x, y)) {
return new VertClick(&fPoly[i]);

View File

@ -722,7 +722,7 @@ protected:
};
virtual Sample::Click* onFindClickHandler(SkScalar x, SkScalar y,
ModifierKey modi) override {
skui::ModifierKey modi) override {
for (size_t i = 0; i < SK_ARRAY_COUNT(fPts); ++i) {
if (hittest(fPts[i], x, y)) {
return new MyClick((int)i);

View File

@ -327,7 +327,7 @@ protected:
}
virtual Sample::Click* onFindClickHandler(SkScalar x, SkScalar y,
ModifierKey modi) override {
skui::ModifierKey modi) override {
return fRect.contains(SkScalarRoundToInt(x),
SkScalarRoundToInt(y)) ? new Click() : nullptr;
}

View File

@ -72,7 +72,7 @@ protected:
fScene->render(canvas);
}
Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey modi) override {
Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
if (auto node = fScene->nodeAt({x, y})) {
Click* click = new Click();
click->fMeta.setPtr("node", (void*)node);

View File

@ -443,7 +443,7 @@ protected:
gProc[fIndex](canvas);
}
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey) override {
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override {
this->init();
fIndex = (fIndex + 1) % SK_ARRAY_COUNT(gProc);
return nullptr;

View File

@ -50,7 +50,7 @@ protected:
canvas->drawPath(path, paint);
}
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey) override {
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override {
fAngle = x/width();
return nullptr;
}

View File

@ -99,7 +99,7 @@ protected:
}
}
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey) override {
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override {
return new Click();
}

View File

@ -160,7 +160,7 @@ protected:
canvas->restore();
}
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, ModifierKey) override {
Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override {
// Check mode buttons first
for (int i = 0; i < N_Modes; ++i) {
if (fModeButtons[i].hitTest(x, y)) {
@ -182,7 +182,7 @@ protected:
bool onClick(Click* click) override {
int32_t mode;
if (click->fMeta.findS32("mode", &mode)) {
if (fSelected && InputState::kUp == click->fState) {
if (fSelected && skui::InputState::kUp == click->fState) {
fSelected->fMode = gModes[mode];
}
} else {

View File

@ -35,8 +35,8 @@ void CommandSet::attach(Window* window) {
fWindow = window;
}
bool CommandSet::onKey(Window::Key key, InputState state, ModifierKey modifiers) {
if (InputState::kDown == state) {
bool CommandSet::onKey(skui::Key key, skui::InputState state, skui::ModifierKey modifiers) {
if (skui::InputState::kDown == state) {
for (Command& cmd : fCommands) {
if (Command::kKey_CommandType == cmd.fType && key == cmd.fKey) {
cmd.fFunction();
@ -48,7 +48,7 @@ bool CommandSet::onKey(Window::Key key, InputState state, ModifierKey modifiers)
return false;
}
bool CommandSet::onChar(SkUnichar c, ModifierKey modifiers) {
bool CommandSet::onChar(SkUnichar c, skui::ModifierKey modifiers) {
for (Command& cmd : fCommands) {
if (Command::kChar_CommandType == cmd.fType && c == cmd.fChar) {
cmd.fFunction();
@ -74,7 +74,7 @@ void CommandSet::addCommand(SkUnichar c, const char* group, const char* descript
fCommands.push_back(Command(c, group, description, function));
}
void CommandSet::addCommand(Window::Key k, const char* keyName, const char* group,
void CommandSet::addCommand(skui::Key k, const char* keyName, const char* group,
const char* description, std::function<void(void)> function) {
fCommands.push_back(Command(k, keyName, group, description, function));
}

View File

@ -41,13 +41,13 @@ public:
CommandSet();
void attach(Window* window);
bool onKey(sk_app::Window::Key key, InputState state, ModifierKey modifiers);
bool onChar(SkUnichar, ModifierKey modifiers);
bool onKey(skui::Key key, skui::InputState state, skui::ModifierKey modifiers);
bool onChar(SkUnichar, skui::ModifierKey modifiers);
bool onSoftkey(const SkString& softkey);
void addCommand(SkUnichar c, const char* group, const char* description,
std::function<void(void)> function);
void addCommand(Window::Key k, const char* keyName, const char* group, const char* description,
void addCommand(skui::Key k, const char* keyName, const char* group, const char* description,
std::function<void(void)> function);
void drawHelp(SkCanvas* canvas);
@ -70,7 +70,7 @@ private:
, fDescription(description)
, fFunction(function) {}
Command(Window::Key k, const char* keyName, const char* group, const char* description,
Command(skui::Key k, const char* keyName, const char* group, const char* description,
std::function<void(void)> function)
: fType(kKey_CommandType)
, fKey(k)
@ -85,7 +85,7 @@ private:
SkUnichar fChar;
// For kKey_CommandType
Window::Key fKey;
skui::Key fKey;
// Common to all command types
SkString fKeyName;

View File

@ -40,23 +40,23 @@ void Window::onBackendCreated() {
this->visitLayers([](Layer* layer) { layer->onBackendCreated(); });
}
bool Window::onChar(SkUnichar c, ModifierKey modifiers) {
bool Window::onChar(SkUnichar c, skui::ModifierKey modifiers) {
return this->signalLayers([=](Layer* layer) { return layer->onChar(c, modifiers); });
}
bool Window::onKey(Key key, InputState state, ModifierKey modifiers) {
bool Window::onKey(skui::Key key, skui::InputState state, skui::ModifierKey modifiers) {
return this->signalLayers([=](Layer* layer) { return layer->onKey(key, state, modifiers); });
}
bool Window::onMouse(int x, int y, InputState state, ModifierKey modifiers) {
bool Window::onMouse(int x, int y, skui::InputState state, skui::ModifierKey modifiers) {
return this->signalLayers([=](Layer* layer) { return layer->onMouse(x, y, state, modifiers); });
}
bool Window::onMouseWheel(float delta, ModifierKey modifiers) {
bool Window::onMouseWheel(float delta, skui::ModifierKey modifiers) {
return this->signalLayers([=](Layer* layer) { return layer->onMouseWheel(delta, modifiers); });
}
bool Window::onTouch(intptr_t owner, InputState state, float x, float y) {
bool Window::onTouch(intptr_t owner, skui::InputState state, float x, float y) {
return this->signalLayers([=](Layer* layer) { return layer->onTouch(owner, state, x, y); });
}

View File

@ -11,9 +11,10 @@
#include "include/core/SkRect.h"
#include "include/core/SkTypes.h"
#include "include/private/SkTDArray.h"
#include "tools/InputState.h"
#include "tools/ModifierKey.h"
#include "tools/sk_app/DisplayParams.h"
#include "tools/skui/InputState.h"
#include "tools/skui/Key.h"
#include "tools/skui/ModifierKey.h"
class GrContext;
class SkCanvas;
@ -69,61 +70,6 @@ public:
void detach();
// input handling
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,
// Keys needed by ImGui
kTab,
kPageUp,
kPageDown,
kDelete,
kEscape,
kShift,
kCtrl,
kOption, // AKA Alt
kA,
kC,
kV,
kX,
kY,
kZ,
kOK, //!< the center key
kVolUp, //!< volume up - match android
kVolDown, //!< volume down - same
kPower, //!< power button - same
kCamera, //!< camera - same
kLast = kCamera
};
static const int kKeyCount = static_cast<int>(Key::kLast) + 1;
class Layer {
public:
@ -136,11 +82,11 @@ public:
// return value of 'true' means 'I have handled this event'
virtual void onBackendCreated() {}
virtual void onAttach(Window* window) {}
virtual bool onChar(SkUnichar c, ModifierKey modifiers) { return false; }
virtual bool onKey(Key key, InputState state, ModifierKey modifiers) { return false; }
virtual bool onMouse(int x, int y, InputState state, ModifierKey modifiers) { return false; }
virtual bool onMouseWheel(float delta, ModifierKey modifiers) { return false; }
virtual bool onTouch(intptr_t owner, InputState state, float x, float y) { return false; }
virtual bool onChar(SkUnichar c, skui::ModifierKey) { return false; }
virtual bool onKey(skui::Key, skui::InputState, skui::ModifierKey) { return false; }
virtual bool onMouse(int x, int y, skui::InputState, skui::ModifierKey) { return false; }
virtual bool onMouseWheel(float delta, skui::ModifierKey) { return false; }
virtual bool onTouch(intptr_t owner, skui::InputState, float x, float y) { return false; }
virtual void onUIStateChanged(const SkString& stateName, const SkString& stateValue) {}
virtual void onPrePaint() {}
virtual void onPaint(SkSurface*) {}
@ -157,11 +103,11 @@ public:
}
void onBackendCreated();
bool onChar(SkUnichar c, ModifierKey modifiers);
bool onKey(Key key, InputState state, ModifierKey modifiers);
bool onMouse(int x, int y, InputState state, ModifierKey modifiers);
bool onMouseWheel(float delta, ModifierKey modifiers);
bool onTouch(intptr_t owner, InputState state, float x, float y); // multi-owner = multi-touch
bool onChar(SkUnichar c, skui::ModifierKey modifiers);
bool onKey(skui::Key key, skui::InputState state, skui::ModifierKey modifiers);
bool onMouse(int x, int y, skui::InputState state, skui::ModifierKey modifiers);
bool onMouseWheel(float delta, skui::ModifierKey modifiers);
bool onTouch(intptr_t owner, skui::InputState state, float x, float y); // multi-owner = multi-touch
void onUIStateChanged(const SkString& stateName, const SkString& stateValue);
void onPaint();
void onResize(int width, int height);

View File

@ -54,18 +54,18 @@ static void config_resource_mgr(JNIEnv* env, jobject assetManager) {
static const int LOOPER_ID_MESSAGEPIPE = 1;
static const std::unordered_map<int, Window::Key> ANDROID_TO_WINDOW_KEYMAP({
{AKEYCODE_SOFT_LEFT, Window::Key::kLeft},
{AKEYCODE_SOFT_RIGHT, Window::Key::kRight}
static const std::unordered_map<int, skui::Key> ANDROID_TO_WINDOW_KEYMAP({
{AKEYCODE_SOFT_LEFT, skui::Key::kLeft },
{AKEYCODE_SOFT_RIGHT, skui::Key::kRight}
});
static const std::unordered_map<int, InputState> ANDROID_TO_WINDOW_STATEMAP({
{AMOTION_EVENT_ACTION_DOWN, InputState::kDown},
{AMOTION_EVENT_ACTION_POINTER_DOWN, InputState::kDown},
{AMOTION_EVENT_ACTION_UP, InputState::kUp},
{AMOTION_EVENT_ACTION_POINTER_UP, InputState::kUp},
{AMOTION_EVENT_ACTION_MOVE, InputState::kMove},
{AMOTION_EVENT_ACTION_CANCEL, InputState::kUp},
static const std::unordered_map<int, skui::InputState> ANDROID_TO_WINDOW_STATEMAP({
{AMOTION_EVENT_ACTION_DOWN, skui::InputState::kDown },
{AMOTION_EVENT_ACTION_POINTER_DOWN, skui::InputState::kDown },
{AMOTION_EVENT_ACTION_UP, skui::InputState::kUp },
{AMOTION_EVENT_ACTION_POINTER_UP, skui::InputState::kUp },
{AMOTION_EVENT_ACTION_MOVE, skui::InputState::kMove },
{AMOTION_EVENT_ACTION_CANCEL, skui::InputState::kUp },
});
SkiaAndroidApp::SkiaAndroidApp(JNIEnv* env, jobject androidApp) {
@ -166,8 +166,8 @@ int SkiaAndroidApp::message_callback(int fd, int events, void* data) {
auto it = ANDROID_TO_WINDOW_KEYMAP.find(message.fKeycode);
SkASSERT(it != ANDROID_TO_WINDOW_KEYMAP.end());
// No modifier is supported so far
skiaAndroidApp->fWindow->onKey(it->second, InputState::kDown, ModifierKey::kNone);
skiaAndroidApp->fWindow->onKey(it->second, InputState::kUp, ModifierKey::kNone);
skiaAndroidApp->fWindow->onKey(it->second, skui::InputState::kDown, skui::ModifierKey::kNone);
skiaAndroidApp->fWindow->onKey(it->second, skui::InputState::kUp, skui::ModifierKey::kNone);
break;
}
case kTouched: {

View File

@ -6,9 +6,9 @@
*/
#include "src/core/SkUtils.h"
#include "tools/ModifierKey.h"
#include "tools/sk_app/ios/WindowContextFactory_ios.h"
#include "tools/sk_app/ios/Window_ios.h"
#include "tools/skui/ModifierKey.h"
#include "tools/timer/Timer.h"
namespace sk_app {
@ -96,57 +96,57 @@ void Window_ios::closeWindow() {
}
}
static Window::Key get_key(const SDL_Keysym& keysym) {
static skui::Key get_key(const SDL_Keysym& keysym) {
static const struct {
SDL_Keycode fSDLK;
Window::Key fKey;
skui::Key fKey;
} gPair[] = {
{ SDLK_BACKSPACE, Window::Key::kBack },
{ SDLK_CLEAR, Window::Key::kBack },
{ SDLK_RETURN, Window::Key::kOK },
{ SDLK_UP, Window::Key::kUp },
{ SDLK_DOWN, Window::Key::kDown },
{ SDLK_LEFT, Window::Key::kLeft },
{ SDLK_RIGHT, Window::Key::kRight },
{ SDLK_TAB, Window::Key::kTab },
{ SDLK_PAGEUP, Window::Key::kPageUp },
{ SDLK_PAGEDOWN, Window::Key::kPageDown },
{ SDLK_HOME, Window::Key::kHome },
{ SDLK_END, Window::Key::kEnd },
{ SDLK_DELETE, Window::Key::kDelete },
{ SDLK_ESCAPE, Window::Key::kEscape },
{ SDLK_LSHIFT, Window::Key::kShift },
{ SDLK_RSHIFT, Window::Key::kShift },
{ SDLK_LCTRL, Window::Key::kCtrl },
{ SDLK_RCTRL, Window::Key::kCtrl },
{ SDLK_LALT, Window::Key::kOption },
{ SDLK_LALT, Window::Key::kOption },
{ 'A', Window::Key::kA },
{ 'C', Window::Key::kC },
{ 'V', Window::Key::kV },
{ 'X', Window::Key::kX },
{ 'Y', Window::Key::kY },
{ 'Z', Window::Key::kZ },
{ SDLK_BACKSPACE, skui::Key::kBack },
{ SDLK_CLEAR, skui::Key::kBack },
{ SDLK_RETURN, skui::Key::kOK },
{ SDLK_UP, skui::Key::kUp },
{ SDLK_DOWN, skui::Key::kDown },
{ SDLK_LEFT, skui::Key::kLeft },
{ SDLK_RIGHT, skui::Key::kRight },
{ SDLK_TAB, skui::Key::kTab },
{ SDLK_PAGEUP, skui::Key::kPageUp },
{ SDLK_PAGEDOWN, skui::Key::kPageDown },
{ SDLK_HOME, skui::Key::kHome },
{ SDLK_END, skui::Key::kEnd },
{ SDLK_DELETE, skui::Key::kDelete },
{ SDLK_ESCAPE, skui::Key::kEscape },
{ SDLK_LSHIFT, skui::Key::kShift },
{ SDLK_RSHIFT, skui::Key::kShift },
{ SDLK_LCTRL, skui::Key::kCtrl },
{ SDLK_RCTRL, skui::Key::kCtrl },
{ SDLK_LALT, skui::Key::kOption },
{ SDLK_LALT, skui::Key::kOption },
{ 'A', skui::Key::kA },
{ 'C', skui::Key::kC },
{ 'V', skui::Key::kV },
{ 'X', skui::Key::kX },
{ 'Y', skui::Key::kY },
{ 'Z', skui::Key::kZ },
};
for (size_t i = 0; i < SK_ARRAY_COUNT(gPair); i++) {
if (gPair[i].fSDLK == keysym.sym) {
return gPair[i].fKey;
}
}
return Window::Key::kNONE;
return skui::Key::kNONE;
}
static ModifierKey get_modifiers(const SDL_Event& event) {
static skui::ModifierKey get_modifiers(const SDL_Event& event) {
static const struct {
unsigned fSDLMask;
ModifierKey fSkMask;
skui::ModifierKey fSkMask;
} gModifiers[] = {
{ KMOD_SHIFT, ModifierKey::kShift },
{ KMOD_CTRL, ModifierKey::kControl },
{ KMOD_ALT, ModifierKey::kOption },
{ KMOD_SHIFT, skui::ModifierKey::kShift },
{ KMOD_CTRL, skui::ModifierKey::kControl },
{ KMOD_ALT, skui::ModifierKey::kOption },
};
ModifierKey modifiers = ModifierKey::kNone;
skui::ModifierKey modifiers = skui::ModifierKey::kNone;
switch (event.type) {
case SDL_KEYDOWN:
@ -158,7 +158,7 @@ static ModifierKey get_modifiers(const SDL_Event& event) {
}
}
if (0 == event.key.repeat) {
modifiers |= ModifierKey::kFirstPress;
modifiers |= skui::ModifierKey::kFirstPress;
}
break;
}
@ -196,27 +196,27 @@ bool Window_ios::handleEvent(const SDL_Event& event) {
break;
case SDL_FINGERDOWN:
this->onTouch(event.tfinger.fingerId, InputState::kDown,
this->onTouch(event.tfinger.fingerId, skui::InputState::kDown,
(int)(this->width()*event.tfinger.x),
(int)(this->height()*event.tfinger.y));
break;
case SDL_FINGERUP:
this->onTouch(event.tfinger.fingerId, InputState::kUp,
this->onTouch(event.tfinger.fingerId, skui::InputState::kUp,
(int)(this->width()*event.tfinger.x),
(int)(this->height()*event.tfinger.y));
break;
case SDL_FINGERMOTION:
this->onTouch(event.tfinger.fingerId, InputState::kMove,
this->onTouch(event.tfinger.fingerId, skui::InputState::kMove,
(int)(this->width()*event.tfinger.x),
(int)(this->height()*event.tfinger.y));
break;
case SDL_KEYDOWN: {
Window::Key key = get_key(event.key.keysym);
if (key != Window::Key::kNONE) {
if (!this->onKey(key, InputState::kDown, get_modifiers(event))) {
skui::Key key = get_key(event.key.keysym);
if (key != skui::Key::kNONE) {
if (!this->onKey(key, skui::InputState::kDown, get_modifiers(event))) {
if (event.key.keysym.sym == SDLK_ESCAPE) {
return true;
}
@ -225,9 +225,9 @@ bool Window_ios::handleEvent(const SDL_Event& event) {
} break;
case SDL_KEYUP: {
Window::Key key = get_key(event.key.keysym);
if (key != Window::Key::kNONE) {
(void) this->onKey(key, InputState::kUp,
skui::Key key = get_key(event.key.keysym);
if (key != skui::Key::kNONE) {
(void) this->onKey(key, skui::InputState::kUp,
get_modifiers(event));
}
} break;

View File

@ -6,9 +6,9 @@
*/
#include "src/core/SkUtils.h"
#include "tools/ModifierKey.h"
#include "tools/sk_app/mac/WindowContextFactory_mac.h"
#include "tools/sk_app/mac/Window_mac.h"
#include "tools/skui/ModifierKey.h"
@interface WindowDelegate : NSObject<NSWindowDelegate>
@ -188,38 +188,38 @@ void Window_mac::PaintWindows() {
///////////////////////////////////////////////////////////////////////////////
static Window::Key get_key(unsigned short vk) {
static skui::Key get_key(unsigned short vk) {
// This will work with an ANSI QWERTY keyboard.
// Something more robust would be needed to support alternate keyboards.
static const struct {
unsigned short fVK;
Window::Key fKey;
skui::Key fKey;
} gPair[] = {
{ 0x33, Window::Key::kBack },
{ 0x24, Window::Key::kOK },
{ 0x7E, Window::Key::kUp },
{ 0x7D, Window::Key::kDown },
{ 0x7B, Window::Key::kLeft },
{ 0x7C, Window::Key::kRight },
{ 0x30, Window::Key::kTab },
{ 0x74, Window::Key::kPageUp },
{ 0x79, Window::Key::kPageDown },
{ 0x73, Window::Key::kHome },
{ 0x77, Window::Key::kEnd },
{ 0x75, Window::Key::kDelete },
{ 0x35, Window::Key::kEscape },
{ 0x38, Window::Key::kShift },
{ 0x3C, Window::Key::kShift },
{ 0x3B, Window::Key::kCtrl },
{ 0x3E, Window::Key::kCtrl },
{ 0x3A, Window::Key::kOption },
{ 0x3D, Window::Key::kOption },
{ 0x00, Window::Key::kA },
{ 0x08, Window::Key::kC },
{ 0x09, Window::Key::kV },
{ 0x07, Window::Key::kX },
{ 0x10, Window::Key::kY },
{ 0x06, Window::Key::kZ },
{ 0x33, skui::Key::kBack },
{ 0x24, skui::Key::kOK },
{ 0x7E, skui::Key::kUp },
{ 0x7D, skui::Key::kDown },
{ 0x7B, skui::Key::kLeft },
{ 0x7C, skui::Key::kRight },
{ 0x30, skui::Key::kTab },
{ 0x74, skui::Key::kPageUp },
{ 0x79, skui::Key::kPageDown },
{ 0x73, skui::Key::kHome },
{ 0x77, skui::Key::kEnd },
{ 0x75, skui::Key::kDelete },
{ 0x35, skui::Key::kEscape },
{ 0x38, skui::Key::kShift },
{ 0x3C, skui::Key::kShift },
{ 0x3B, skui::Key::kCtrl },
{ 0x3E, skui::Key::kCtrl },
{ 0x3A, skui::Key::kOption },
{ 0x3D, skui::Key::kOption },
{ 0x00, skui::Key::kA },
{ 0x08, skui::Key::kC },
{ 0x09, skui::Key::kV },
{ 0x07, skui::Key::kX },
{ 0x10, skui::Key::kY },
{ 0x06, skui::Key::kZ },
};
for (size_t i = 0; i < SK_ARRAY_COUNT(gPair); i++) {
if (gPair[i].fVK == vk) {
@ -227,29 +227,29 @@ static Window::Key get_key(unsigned short vk) {
}
}
return Window::Key::kNONE;
return skui::Key::kNONE;
}
static ModifierKey get_modifiers(const NSEvent* event) {
static skui::ModifierKey get_modifiers(const NSEvent* event) {
NSUInteger modifierFlags = [event modifierFlags];
ModifierKey modifiers = ModifierKey::kNone;
skui::ModifierKey modifiers = skui::ModifierKey::kNone;
if (modifierFlags & NSEventModifierFlagCommand) {
modifiers |= ModifierKey::kCommand;
modifiers |= skui::ModifierKey::kCommand;
}
if (modifierFlags & NSEventModifierFlagShift) {
modifiers |= ModifierKey::kShift;
modifiers |= skui::ModifierKey::kShift;
}
if (modifierFlags & NSEventModifierFlagControl) {
modifiers |= ModifierKey::kControl;
modifiers |= skui::ModifierKey::kControl;
}
if (modifierFlags & NSEventModifierFlagOption) {
modifiers |= ModifierKey::kOption;
modifiers |= skui::ModifierKey::kOption;
}
if ((NSKeyDown == [event type] || NSKeyUp == [event type]) &&
NO == [event isARepeat]) {
modifiers |= ModifierKey::kFirstPress;
modifiers |= skui::ModifierKey::kFirstPress;
}
return modifiers;
@ -313,10 +313,10 @@ static ModifierKey get_modifiers(const NSEvent* event) {
}
- (void)keyDown:(NSEvent *)event {
Window::Key key = get_key([event keyCode]);
if (key != Window::Key::kNONE) {
if (!fWindow->onKey(key, InputState::kDown, get_modifiers(event))) {
if (Window::Key::kEscape == key) {
skui::Key key = get_key([event keyCode]);
if (key != skui::Key::kNONE) {
if (!fWindow->onKey(key, skui::InputState::kDown, get_modifiers(event))) {
if (skui::Key::kEscape == key) {
[NSApp terminate:fWindow->window()];
}
}
@ -335,23 +335,23 @@ static ModifierKey get_modifiers(const NSEvent* event) {
}
- (void)keyUp:(NSEvent *)event {
Window::Key key = get_key([event keyCode]);
if (key != Window::Key::kNONE) {
(void) fWindow->onKey(key, InputState::kUp, get_modifiers(event));
skui::Key key = get_key([event keyCode]);
if (key != skui::Key::kNONE) {
(void) fWindow->onKey(key, skui::InputState::kUp, get_modifiers(event));
}
}
- (void)mouseDown:(NSEvent *)event {
const NSPoint pos = [event locationInWindow];
const NSRect rect = [fWindow->window().contentView frame];
fWindow->onMouse(pos.x, rect.size.height - pos.y, InputState::kDown,
fWindow->onMouse(pos.x, rect.size.height - pos.y, skui::InputState::kDown,
get_modifiers(event));
}
- (void)mouseUp:(NSEvent *)event {
const NSPoint pos = [event locationInWindow];
const NSRect rect = [fWindow->window().contentView frame];
fWindow->onMouse(pos.x, rect.size.height - pos.y, InputState::kUp,
fWindow->onMouse(pos.x, rect.size.height - pos.y, skui::InputState::kUp,
get_modifiers(event));
}
@ -362,7 +362,7 @@ static ModifierKey get_modifiers(const NSEvent* event) {
- (void)mouseMoved:(NSEvent *)event {
const NSPoint pos = [event locationInWindow];
const NSRect rect = [fWindow->window().contentView frame];
fWindow->onMouse(pos.x, rect.size.height - pos.y, InputState::kMove,
fWindow->onMouse(pos.x, rect.size.height - pos.y, skui::InputState::kMove,
get_modifiers(event));
}

View File

@ -15,9 +15,9 @@
#include "tools/sk_app/unix/WindowContextFactory_unix.h"
#include "src/utils/SkUTF.h"
#include "tools/ModifierKey.h"
#include "tools/sk_app/GLWindowContext.h"
#include "tools/sk_app/unix/Window_unix.h"
#include "tools/skui/ModifierKey.h"
#include "tools/timer/Timer.h"
extern "C" {
@ -190,57 +190,57 @@ void Window_unix::closeWindow() {
}
}
static Window::Key get_key(KeySym keysym) {
static skui::Key get_key(KeySym keysym) {
static const struct {
KeySym fXK;
Window::Key fKey;
skui::Key fKey;
} gPair[] = {
{ XK_BackSpace, Window::Key::kBack },
{ XK_Clear, Window::Key::kBack },
{ XK_Return, Window::Key::kOK },
{ XK_Up, Window::Key::kUp },
{ XK_Down, Window::Key::kDown },
{ XK_Left, Window::Key::kLeft },
{ XK_Right, Window::Key::kRight },
{ XK_Tab, Window::Key::kTab },
{ XK_Page_Up, Window::Key::kPageUp },
{ XK_Page_Down, Window::Key::kPageDown },
{ XK_Home, Window::Key::kHome },
{ XK_End, Window::Key::kEnd },
{ XK_Delete, Window::Key::kDelete },
{ XK_Escape, Window::Key::kEscape },
{ XK_Shift_L, Window::Key::kShift },
{ XK_Shift_R, Window::Key::kShift },
{ XK_Control_L, Window::Key::kCtrl },
{ XK_Control_R, Window::Key::kCtrl },
{ XK_Alt_L, Window::Key::kOption },
{ XK_Alt_R, Window::Key::kOption },
{ 'A', Window::Key::kA },
{ 'C', Window::Key::kC },
{ 'V', Window::Key::kV },
{ 'X', Window::Key::kX },
{ 'Y', Window::Key::kY },
{ 'Z', Window::Key::kZ },
{ XK_BackSpace, skui::Key::kBack },
{ XK_Clear, skui::Key::kBack },
{ XK_Return, skui::Key::kOK },
{ XK_Up, skui::Key::kUp },
{ XK_Down, skui::Key::kDown },
{ XK_Left, skui::Key::kLeft },
{ XK_Right, skui::Key::kRight },
{ XK_Tab, skui::Key::kTab },
{ XK_Page_Up, skui::Key::kPageUp },
{ XK_Page_Down, skui::Key::kPageDown },
{ XK_Home, skui::Key::kHome },
{ XK_End, skui::Key::kEnd },
{ XK_Delete, skui::Key::kDelete },
{ XK_Escape, skui::Key::kEscape },
{ XK_Shift_L, skui::Key::kShift },
{ XK_Shift_R, skui::Key::kShift },
{ XK_Control_L, skui::Key::kCtrl },
{ XK_Control_R, skui::Key::kCtrl },
{ XK_Alt_L, skui::Key::kOption },
{ XK_Alt_R, skui::Key::kOption },
{ 'A', skui::Key::kA },
{ 'C', skui::Key::kC },
{ 'V', skui::Key::kV },
{ 'X', skui::Key::kX },
{ 'Y', skui::Key::kY },
{ 'Z', skui::Key::kZ },
};
for (size_t i = 0; i < SK_ARRAY_COUNT(gPair); i++) {
if (gPair[i].fXK == keysym) {
return gPair[i].fKey;
}
}
return Window::Key::kNONE;
return skui::Key::kNONE;
}
static ModifierKey get_modifiers(const XEvent& event) {
static skui::ModifierKey get_modifiers(const XEvent& event) {
static const struct {
unsigned fXMask;
ModifierKey fSkMask;
skui::ModifierKey fSkMask;
} gModifiers[] = {
{ ShiftMask, ModifierKey::kShift },
{ ControlMask, ModifierKey::kControl },
{ Mod1Mask, ModifierKey::kOption },
{ ShiftMask, skui::ModifierKey::kShift },
{ ControlMask, skui::ModifierKey::kControl },
{ Mod1Mask, skui::ModifierKey::kOption },
};
ModifierKey modifiers = ModifierKey::kNone;
skui::ModifierKey modifiers = skui::ModifierKey::kNone;
for (size_t i = 0; i < SK_ARRAY_COUNT(gModifiers); ++i) {
if (event.xkey.state & gModifiers[i].fXMask) {
modifiers |= gModifiers[i].fSkMask;
@ -268,7 +268,7 @@ bool Window_unix::handleEvent(const XEvent& event) {
switch (event.xbutton.button) {
case Button1:
this->onMouse(event.xbutton.x, event.xbutton.y,
InputState::kDown, get_modifiers(event));
skui::InputState::kDown, get_modifiers(event));
break;
case Button4:
this->onMouseWheel(1.0f, get_modifiers(event));
@ -282,21 +282,21 @@ bool Window_unix::handleEvent(const XEvent& event) {
case ButtonRelease:
if (event.xbutton.button == Button1) {
this->onMouse(event.xbutton.x, event.xbutton.y,
InputState::kUp, get_modifiers(event));
skui::InputState::kUp, get_modifiers(event));
}
break;
case MotionNotify:
this->onMouse(event.xmotion.x, event.xmotion.y,
InputState::kMove, get_modifiers(event));
skui::InputState::kMove, get_modifiers(event));
break;
case KeyPress: {
int shiftLevel = (event.xkey.state & ShiftMask) ? 1 : 0;
KeySym keysym = XkbKeycodeToKeysym(fDisplay, event.xkey.keycode, 0, shiftLevel);
Window::Key key = get_key(keysym);
if (key != Window::Key::kNONE) {
if (!this->onKey(key, InputState::kDown, get_modifiers(event))) {
skui::Key key = get_key(keysym);
if (key != skui::Key::kNONE) {
if (!this->onKey(key, skui::InputState::kDown, get_modifiers(event))) {
if (keysym == XK_Escape) {
return true;
}
@ -313,8 +313,8 @@ bool Window_unix::handleEvent(const XEvent& event) {
int shiftLevel = (event.xkey.state & ShiftMask) ? 1 : 0;
KeySym keysym = XkbKeycodeToKeysym(fDisplay, event.xkey.keycode,
0, shiftLevel);
Window::Key key = get_key(keysym);
(void) this->onKey(key, InputState::kUp,
skui::Key key = get_key(keysym);
(void) this->onKey(key, skui::InputState::kUp,
get_modifiers(event));
} break;

View File

@ -14,9 +14,9 @@
#include <windowsx.h>
#include "src/core/SkUtils.h"
#include "tools/ModifierKey.h"
#include "tools/sk_app/WindowContext.h"
#include "tools/sk_app/win/WindowContextFactory_win.h"
#include "tools/skui/ModifierKey.h"
#ifdef SK_VULKAN
#include "tools/sk_app/VulkanWindowContext.h"
@ -123,71 +123,71 @@ bool Window_win::init(HINSTANCE hInstance) {
return true;
}
static Window::Key get_key(WPARAM vk) {
static skui::Key get_key(WPARAM vk) {
static const struct {
WPARAM fVK;
Window::Key fKey;
skui::Key fKey;
} gPair[] = {
{ VK_BACK, Window::Key::kBack },
{ VK_CLEAR, Window::Key::kBack },
{ VK_RETURN, Window::Key::kOK },
{ VK_UP, Window::Key::kUp },
{ VK_DOWN, Window::Key::kDown },
{ VK_LEFT, Window::Key::kLeft },
{ VK_RIGHT, Window::Key::kRight },
{ VK_TAB, Window::Key::kTab },
{ VK_PRIOR, Window::Key::kPageUp },
{ VK_NEXT, Window::Key::kPageDown },
{ VK_HOME, Window::Key::kHome },
{ VK_END, Window::Key::kEnd },
{ VK_DELETE, Window::Key::kDelete },
{ VK_ESCAPE, Window::Key::kEscape },
{ VK_SHIFT, Window::Key::kShift },
{ VK_CONTROL, Window::Key::kCtrl },
{ VK_MENU, Window::Key::kOption },
{ 'A', Window::Key::kA },
{ 'C', Window::Key::kC },
{ 'V', Window::Key::kV },
{ 'X', Window::Key::kX },
{ 'Y', Window::Key::kY },
{ 'Z', Window::Key::kZ },
{ VK_BACK, skui::Key::kBack },
{ VK_CLEAR, skui::Key::kBack },
{ VK_RETURN, skui::Key::kOK },
{ VK_UP, skui::Key::kUp },
{ VK_DOWN, skui::Key::kDown },
{ VK_LEFT, skui::Key::kLeft },
{ VK_RIGHT, skui::Key::kRight },
{ VK_TAB, skui::Key::kTab },
{ VK_PRIOR, skui::Key::kPageUp },
{ VK_NEXT, skui::Key::kPageDown },
{ VK_HOME, skui::Key::kHome },
{ VK_END, skui::Key::kEnd },
{ VK_DELETE, skui::Key::kDelete },
{ VK_ESCAPE, skui::Key::kEscape },
{ VK_SHIFT, skui::Key::kShift },
{ VK_CONTROL, skui::Key::kCtrl },
{ VK_MENU, skui::Key::kOption },
{ 'A', skui::Key::kA },
{ 'C', skui::Key::kC },
{ 'V', skui::Key::kV },
{ 'X', skui::Key::kX },
{ 'Y', skui::Key::kY },
{ 'Z', skui::Key::kZ },
};
for (size_t i = 0; i < SK_ARRAY_COUNT(gPair); i++) {
if (gPair[i].fVK == vk) {
return gPair[i].fKey;
}
}
return Window::Key::kNONE;
return skui::Key::kNONE;
}
static ModifierKey get_modifiers(UINT message, WPARAM wParam, LPARAM lParam) {
ModifierKey modifiers = ModifierKey::kNone;
static skui::ModifierKey get_modifiers(UINT message, WPARAM wParam, LPARAM lParam) {
skui::ModifierKey modifiers = skui::ModifierKey::kNone;
switch (message) {
case WM_UNICHAR:
case WM_CHAR:
if (0 == (lParam & (1 << 30))) {
modifiers |= ModifierKey::kFirstPress;
modifiers |= skui::ModifierKey::kFirstPress;
}
if (lParam & (1 << 29)) {
modifiers |= ModifierKey::kOption;
modifiers |= skui::ModifierKey::kOption;
}
break;
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
if (0 == (lParam & (1 << 30))) {
modifiers |= ModifierKey::kFirstPress;
modifiers |= skui::ModifierKey::kFirstPress;
}
if (lParam & (1 << 29)) {
modifiers |= ModifierKey::kOption;
modifiers |= skui::ModifierKey::kOption;
}
break;
case WM_KEYUP:
case WM_SYSKEYUP:
if (lParam & (1 << 29)) {
modifiers |= ModifierKey::kOption;
modifiers |= skui::ModifierKey::kOption;
}
break;
@ -196,10 +196,10 @@ static ModifierKey get_modifiers(UINT message, WPARAM wParam, LPARAM lParam) {
case WM_MOUSEMOVE:
case WM_MOUSEWHEEL:
if (wParam & MK_CONTROL) {
modifiers |= ModifierKey::kControl;
modifiers |= skui::ModifierKey::kControl;
}
if (wParam & MK_SHIFT) {
modifiers |= ModifierKey::kShift;
modifiers |= skui::ModifierKey::kShift;
}
break;
}
@ -251,13 +251,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
eventHandled = window->onKey(get_key(wParam), InputState::kDown,
eventHandled = window->onKey(get_key(wParam), skui::InputState::kDown,
get_modifiers(message, wParam, lParam));
break;
case WM_KEYUP:
case WM_SYSKEYUP:
eventHandled = window->onKey(get_key(wParam), InputState::kUp,
eventHandled = window->onKey(get_key(wParam), skui::InputState::kUp,
get_modifiers(message, wParam, lParam));
break;
@ -274,8 +274,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
// yPos -= rc.top;
//}
InputState istate = ((wParam & MK_LBUTTON) != 0) ? InputState::kDown
: InputState::kUp;
skui::InputState istate = ((wParam & MK_LBUTTON) != 0) ? skui::InputState::kDown
: skui::InputState::kUp;
eventHandled = window->onMouse(xPos, yPos, istate,
get_modifiers(message, wParam, lParam));
@ -293,7 +293,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
// yPos -= rc.top;
//}
eventHandled = window->onMouse(xPos, yPos, InputState::kMove,
eventHandled = window->onMouse(xPos, yPos, skui::InputState::kMove,
get_modifiers(message, wParam, lParam));
} break;
@ -311,13 +311,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
ClientToScreen(hWnd, &topLeft);
for (uint16_t i = 0; i < numInputs; ++i) {
TOUCHINPUT ti = inputs[i];
InputState state;
skui::InputState state;
if (ti.dwFlags & TOUCHEVENTF_DOWN) {
state = InputState::kDown;
state = skui::InputState::kDown;
} else if (ti.dwFlags & TOUCHEVENTF_MOVE) {
state = InputState::kMove;
state = skui::InputState::kMove;
} else if (ti.dwFlags & TOUCHEVENTF_UP) {
state = InputState::kUp;
state = skui::InputState::kUp;
} else {
continue;
}

View File

@ -1,10 +1,12 @@
// Copyright 2019 Google LLC.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#ifndef InputState_DEFINED
#define InputState_DEFINED
#ifndef skui_inputstate_DEFINED
#define skui_inputstate_DEFINED
namespace skui {
enum class InputState {
kDown,
kUp,
kMove // only valid for mouse
};
#endif // InputState_DEFINED
}
#endif // skui_inputstate_DEFINED

59
tools/skui/Key.h Normal file
View File

@ -0,0 +1,59 @@
// Copyright 2019 Google LLC.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#ifndef skui_key_DEFINED
#define skui_key_DEFINED
namespace skui {
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,
// Keys needed by ImGui
kTab,
kPageUp,
kPageDown,
kDelete,
kEscape,
kShift,
kCtrl,
kOption, // AKA Alt
kA,
kC,
kV,
kX,
kY,
kZ,
kOK, //!< the center key
kVolUp, //!< volume up - match android
kVolDown, //!< volume down - same
kPower, //!< power button - same
kCamera, //!< camera - same
};
}
#endif // skui_key_DEFINED

View File

@ -1,10 +1,11 @@
// Copyright 2019 Google LLC.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#ifndef ModifierKey_DEFINED
#define ModifierKey_DEFINED
#ifndef skui_modifierkey_defined
#define skui_modifierkey_defined
#include "include/private/SkBitmaskEnum.h"
namespace skui {
enum class ModifierKey {
kNone = 0,
kShift = 1 << 0,
@ -13,9 +14,9 @@ enum class ModifierKey {
kCommand = 1 << 3,
kFirstPress = 1 << 4,
};
namespace skstd {
template <> struct is_bitmask_enum<ModifierKey> : std::true_type {};
}
#endif // ModifierKey_DEFINED
namespace skstd {
template <> struct is_bitmask_enum<skui::ModifierKey> : std::true_type {};
}
#endif // skui_modifierkey_defined

View File

@ -28,25 +28,25 @@ ImGuiLayer::ImGuiLayer() {
ImGuiIO& io = ImGui::GetIO();
// Keymap...
io.KeyMap[ImGuiKey_Tab] = (int)Window::Key::kTab;
io.KeyMap[ImGuiKey_LeftArrow] = (int)Window::Key::kLeft;
io.KeyMap[ImGuiKey_RightArrow] = (int)Window::Key::kRight;
io.KeyMap[ImGuiKey_UpArrow] = (int)Window::Key::kUp;
io.KeyMap[ImGuiKey_DownArrow] = (int)Window::Key::kDown;
io.KeyMap[ImGuiKey_PageUp] = (int)Window::Key::kPageUp;
io.KeyMap[ImGuiKey_PageDown] = (int)Window::Key::kPageDown;
io.KeyMap[ImGuiKey_Home] = (int)Window::Key::kHome;
io.KeyMap[ImGuiKey_End] = (int)Window::Key::kEnd;
io.KeyMap[ImGuiKey_Delete] = (int)Window::Key::kDelete;
io.KeyMap[ImGuiKey_Backspace] = (int)Window::Key::kBack;
io.KeyMap[ImGuiKey_Enter] = (int)Window::Key::kOK;
io.KeyMap[ImGuiKey_Escape] = (int)Window::Key::kEscape;
io.KeyMap[ImGuiKey_A] = (int)Window::Key::kA;
io.KeyMap[ImGuiKey_C] = (int)Window::Key::kC;
io.KeyMap[ImGuiKey_V] = (int)Window::Key::kV;
io.KeyMap[ImGuiKey_X] = (int)Window::Key::kX;
io.KeyMap[ImGuiKey_Y] = (int)Window::Key::kY;
io.KeyMap[ImGuiKey_Z] = (int)Window::Key::kZ;
io.KeyMap[ImGuiKey_Tab] = (int)skui::Key::kTab;
io.KeyMap[ImGuiKey_LeftArrow] = (int)skui::Key::kLeft;
io.KeyMap[ImGuiKey_RightArrow] = (int)skui::Key::kRight;
io.KeyMap[ImGuiKey_UpArrow] = (int)skui::Key::kUp;
io.KeyMap[ImGuiKey_DownArrow] = (int)skui::Key::kDown;
io.KeyMap[ImGuiKey_PageUp] = (int)skui::Key::kPageUp;
io.KeyMap[ImGuiKey_PageDown] = (int)skui::Key::kPageDown;
io.KeyMap[ImGuiKey_Home] = (int)skui::Key::kHome;
io.KeyMap[ImGuiKey_End] = (int)skui::Key::kEnd;
io.KeyMap[ImGuiKey_Delete] = (int)skui::Key::kDelete;
io.KeyMap[ImGuiKey_Backspace] = (int)skui::Key::kBack;
io.KeyMap[ImGuiKey_Enter] = (int)skui::Key::kOK;
io.KeyMap[ImGuiKey_Escape] = (int)skui::Key::kEscape;
io.KeyMap[ImGuiKey_A] = (int)skui::Key::kA;
io.KeyMap[ImGuiKey_C] = (int)skui::Key::kC;
io.KeyMap[ImGuiKey_V] = (int)skui::Key::kV;
io.KeyMap[ImGuiKey_X] = (int)skui::Key::kX;
io.KeyMap[ImGuiKey_Y] = (int)skui::Key::kY;
io.KeyMap[ImGuiKey_Z] = (int)skui::Key::kZ;
int w, h;
unsigned char* pixels;
@ -70,19 +70,19 @@ void ImGuiLayer::onAttach(Window* window) {
fWindow = window;
}
bool ImGuiLayer::onMouse(int x, int y, InputState state, ModifierKey modifiers) {
bool ImGuiLayer::onMouse(int x, int y, skui::InputState state, skui::ModifierKey modifiers) {
ImGuiIO& io = ImGui::GetIO();
io.MousePos.x = static_cast<float>(x);
io.MousePos.y = static_cast<float>(y);
if (InputState::kDown == state) {
if (skui::InputState::kDown == state) {
io.MouseDown[0] = true;
} else if (InputState::kUp == state) {
} else if (skui::InputState::kUp == state) {
io.MouseDown[0] = false;
}
return io.WantCaptureMouse;
}
bool ImGuiLayer::onMouseWheel(float delta, ModifierKey modifiers) {
bool ImGuiLayer::onMouseWheel(float delta, skui::ModifierKey modifiers) {
ImGuiIO& io = ImGui::GetIO();
io.MouseWheel += delta;
return true;
@ -106,9 +106,9 @@ void ImGuiLayer::onPrePaint() {
io.DisplaySize.x = static_cast<float>(fWindow->width());
io.DisplaySize.y = static_cast<float>(fWindow->height());
io.KeyAlt = io.KeysDown[static_cast<int>(Window::Key::kOption)];
io.KeyCtrl = io.KeysDown[static_cast<int>(Window::Key::kCtrl)];
io.KeyShift = io.KeysDown[static_cast<int>(Window::Key::kShift)];
io.KeyAlt = io.KeysDown[static_cast<int>(skui::Key::kOption)];
io.KeyCtrl = io.KeysDown[static_cast<int>(skui::Key::kCtrl)];
io.KeyShift = io.KeysDown[static_cast<int>(skui::Key::kShift)];
ImGui::NewFrame();
}
@ -184,13 +184,13 @@ void ImGuiLayer::onPaint(SkSurface* surface) {
fSkiaWidgetFuncs.reset();
}
bool ImGuiLayer::onKey(sk_app::Window::Key key, InputState state, ModifierKey modifiers) {
bool ImGuiLayer::onKey(skui::Key key, skui::InputState state, skui::ModifierKey modifiers) {
ImGuiIO& io = ImGui::GetIO();
io.KeysDown[static_cast<int>(key)] = (InputState::kDown == state);
io.KeysDown[static_cast<int>(key)] = (skui::InputState::kDown == state);
return io.WantCaptureKeyboard;
}
bool ImGuiLayer::onChar(SkUnichar c, ModifierKey modifiers) {
bool ImGuiLayer::onChar(SkUnichar c, skui::ModifierKey modifiers) {
ImGuiIO& io = ImGui::GetIO();
if (io.WantTextInput) {
if (c > 0 && c < 0x10000) {

View File

@ -123,10 +123,10 @@ public:
void onAttach(sk_app::Window* window) override;
void onPrePaint() override;
void onPaint(SkSurface*) override;
bool onMouse(int x, int y, InputState state, ModifierKey modifiers) override;
bool onMouseWheel(float delta, ModifierKey modifiers) override;
bool onKey(sk_app::Window::Key key, InputState state, ModifierKey modifiers) override;
bool onChar(SkUnichar c, ModifierKey modifiers) override;
bool onMouse(int x, int y, skui::InputState state, skui::ModifierKey modifiers) override;
bool onMouseWheel(float delta, skui::ModifierKey modifiers) override;
bool onKey(skui::Key key, skui::InputState state, skui::ModifierKey modifiers) override;
bool onChar(SkUnichar c, skui::ModifierKey modifiers) override;
private:
sk_app::Window* fWindow;

View File

@ -346,9 +346,9 @@ bool ParticlesSlide::animate(double nanos) {
return true;
}
bool ParticlesSlide::onMouse(SkScalar x, SkScalar y, InputState state, ModifierKey modifiers) {
bool ParticlesSlide::onMouse(SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey modifiers) {
if (gDragIndex == -1) {
if (state == InputState::kDown) {
if (state == skui::InputState::kDown) {
float bestDistance = kDragSize;
SkPoint mousePt = { x, y };
for (int i = 0; i < gDragPoints.count(); ++i) {
@ -364,7 +364,7 @@ bool ParticlesSlide::onMouse(SkScalar x, SkScalar y, InputState state, ModifierK
// Currently dragging
SkASSERT(gDragIndex < gDragPoints.count());
gDragPoints[gDragIndex]->set(x, y);
if (state == InputState::kUp) {
if (state == skui::InputState::kUp) {
gDragIndex = -1;
}
return true;

View File

@ -28,8 +28,8 @@ public:
void draw(SkCanvas* canvas) override;
bool animate(double) override;
bool onMouse(SkScalar x, SkScalar y, InputState state,
ModifierKey modifiers) override;
bool onMouse(SkScalar x, SkScalar y, skui::InputState state,
skui::ModifierKey modifiers) override;
private:
void loadEffects(const char* dirname);

View File

@ -44,6 +44,6 @@ bool SampleSlide::onChar(SkUnichar c) {
return fSample && fSample->onChar(c);
}
bool SampleSlide::onMouse(SkScalar x, SkScalar y, InputState state, ModifierKey modifierKeys) {
bool SampleSlide::onMouse(SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey modifierKeys) {
return fSample && fSample->mouse({x, y}, state, modifierKeys);
}

View File

@ -27,8 +27,8 @@ public:
bool animate(double) override;
bool onChar(SkUnichar c) override;
bool onMouse(SkScalar x, SkScalar y, InputState state,
ModifierKey modifiers) override;
bool onMouse(SkScalar x, SkScalar y, skui::InputState state,
skui::ModifierKey modifiers) override;
private:
const SampleFactory fSampleFactory;

View File

@ -181,9 +181,9 @@ bool SkottieSlide::onChar(SkUnichar c) {
return INHERITED::onChar(c);
}
bool SkottieSlide::onMouse(SkScalar x, SkScalar y, InputState state, ModifierKey) {
bool SkottieSlide::onMouse(SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey) {
switch (state) {
case InputState::kUp:
case skui::InputState::kUp:
fShowAnimationInval = !fShowAnimationInval;
fShowAnimationStats = !fShowAnimationStats;
break;

View File

@ -30,7 +30,7 @@ public:
bool animate(double) override;
bool onChar(SkUnichar) override;
bool onMouse(SkScalar x, SkScalar y, InputState, ModifierKey modifiers) override;
bool onMouse(SkScalar x, SkScalar y, skui::InputState, skui::ModifierKey modifiers) override;
private:
SkString fPath;

View File

@ -29,8 +29,8 @@ public:
virtual void unload() {}
virtual bool onChar(SkUnichar c) { return false; }
virtual bool onMouse(SkScalar x, SkScalar y, InputState state,
ModifierKey modifiers) { return false; }
virtual bool onMouse(SkScalar x, SkScalar y, skui::InputState state,
skui::ModifierKey modifiers) { return false; }
virtual bool onGetControls(SkMetaData*) { return false; }
virtual void onSetControls(const SkMetaData&) {}

View File

@ -158,7 +158,7 @@ public:
fState = State::kUnfocusing;
}
bool onMouse(SkScalar x, SkScalar y, InputState state, ModifierKey modifiers) {
bool onMouse(SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey modifiers) {
SkASSERT(fTarget);
if (!fRect.contains(x, y)) {
@ -379,10 +379,10 @@ bool SlideDir::onChar(SkUnichar c) {
return false;
}
bool SlideDir::onMouse(SkScalar x, SkScalar y, InputState state,
ModifierKey modifiers) {
modifiers &= ~ModifierKey::kFirstPress;
if (state == InputState::kMove || skstd::Any(modifiers))
bool SlideDir::onMouse(SkScalar x, SkScalar y, skui::InputState state,
skui::ModifierKey modifiers) {
modifiers &= ~skui::ModifierKey::kFirstPress;
if (state == skui::InputState::kMove || skstd::Any(modifiers))
return false;
if (fFocusController->hasFocus()) {
@ -396,11 +396,11 @@ bool SlideDir::onMouse(SkScalar x, SkScalar y, InputState state,
static constexpr SkScalar kClickMoveTolerance = 4;
switch (state) {
case InputState::kDown:
case skui::InputState::kDown:
fTrackingCell = cell;
fTrackingPos = SkPoint::Make(x, y);
break;
case InputState::kUp:
case skui::InputState::kUp:
if (cell == fTrackingCell &&
SkPoint::Distance(fTrackingPos, SkPoint::Make(x, y)) < kClickMoveTolerance) {
fFocusController->startFocus(cell);

View File

@ -36,7 +36,7 @@ protected:
bool animate(double) override;
bool onChar(SkUnichar) override;
bool onMouse(SkScalar x, SkScalar y, InputState, ModifierKey modifiers) override;
bool onMouse(SkScalar x, SkScalar y, skui::InputState, skui::ModifierKey modifiers) override;
private:
struct Rec;

View File

@ -335,7 +335,7 @@ Viewer::Viewer(int argc, char** argv, void* platformData)
fWindow->inval();
});
// Alias that to Backspace, to match SampleApp
fCommands.addCommand(Window::Key::kBack, "Backspace", "GUI", "Jump to slide picker", [this]() {
fCommands.addCommand(skui::Key::kBack, "Backspace", "GUI", "Jump to slide picker", [this]() {
this->fShowImGuiDebugWindow = true;
this->fShowSlidePicker = true;
fWindow->inval();
@ -385,17 +385,17 @@ Viewer::Viewer(int argc, char** argv, void* platformData)
break;
}
});
fCommands.addCommand(Window::Key::kRight, "Right", "Navigation", "Next slide", [this]() {
fCommands.addCommand(skui::Key::kRight, "Right", "Navigation", "Next slide", [this]() {
this->setCurrentSlide(fCurrentSlide < fSlides.count() - 1 ? fCurrentSlide + 1 : 0);
});
fCommands.addCommand(Window::Key::kLeft, "Left", "Navigation", "Previous slide", [this]() {
fCommands.addCommand(skui::Key::kLeft, "Left", "Navigation", "Previous slide", [this]() {
this->setCurrentSlide(fCurrentSlide > 0 ? fCurrentSlide - 1 : fSlides.count() - 1);
});
fCommands.addCommand(Window::Key::kUp, "Up", "Transform", "Zoom in", [this]() {
fCommands.addCommand(skui::Key::kUp, "Up", "Transform", "Zoom in", [this]() {
this->changeZoomLevel(1.f / 32.f);
fWindow->inval();
});
fCommands.addCommand(Window::Key::kDown, "Down", "Transform", "Zoom out", [this]() {
fCommands.addCommand(skui::Key::kDown, "Down", "Transform", "Zoom out", [this]() {
this->changeZoomLevel(-1.f / 32.f);
fWindow->inval();
});
@ -1401,20 +1401,20 @@ SkPoint Viewer::mapEvent(float x, float y) {
return inv.mapXY(x, y);
}
bool Viewer::onTouch(intptr_t owner, InputState state, float x, float y) {
bool Viewer::onTouch(intptr_t owner, skui::InputState state, float x, float y) {
if (GestureDevice::kMouse == fGestureDevice) {
return false;
}
const auto slidePt = this->mapEvent(x, y);
if (fSlides[fCurrentSlide]->onMouse(slidePt.x(), slidePt.y(), state, ModifierKey::kNone)) {
if (fSlides[fCurrentSlide]->onMouse(slidePt.x(), slidePt.y(), state, skui::ModifierKey::kNone)) {
fWindow->inval();
return true;
}
void* castedOwner = reinterpret_cast<void*>(owner);
switch (state) {
case InputState::kUp: {
case skui::InputState::kUp: {
fGesture.touchEnd(castedOwner);
#if defined(SK_BUILD_FOR_IOS)
// TODO: move IOS swipe detection higher up into the platform code
@ -1435,11 +1435,11 @@ bool Viewer::onTouch(intptr_t owner, InputState state, float x, float y) {
#endif
break;
}
case InputState::kDown: {
case skui::InputState::kDown: {
fGesture.touchBegin(castedOwner, x, y);
break;
}
case InputState::kMove: {
case skui::InputState::kMove: {
fGesture.touchMoved(castedOwner, x, y);
break;
}
@ -1449,7 +1449,7 @@ bool Viewer::onTouch(intptr_t owner, InputState state, float x, float y) {
return true;
}
bool Viewer::onMouse(int x, int y, InputState state, ModifierKey modifiers) {
bool Viewer::onMouse(int x, int y, skui::InputState state, skui::ModifierKey modifiers) {
if (GestureDevice::kTouch == fGestureDevice) {
return false;
}
@ -1461,22 +1461,22 @@ bool Viewer::onMouse(int x, int y, InputState state, ModifierKey modifiers) {
}
switch (state) {
case InputState::kUp: {
case skui::InputState::kUp: {
fGesture.touchEnd(nullptr);
break;
}
case InputState::kDown: {
case skui::InputState::kDown: {
fGesture.touchBegin(nullptr, x, y);
break;
}
case InputState::kMove: {
case skui::InputState::kMove: {
fGesture.touchMoved(nullptr, x, y);
break;
}
}
fGestureDevice = fGesture.isBeingTouched() ? GestureDevice::kMouse : GestureDevice::kNone;
if (state != InputState::kMove || fGesture.isBeingTouched()) {
if (state != skui::InputState::kMove || fGesture.isBeingTouched()) {
fWindow->inval();
}
return true;
@ -2382,11 +2382,11 @@ void Viewer::onUIStateChanged(const SkString& stateName, const SkString& stateVa
}
}
bool Viewer::onKey(sk_app::Window::Key key, InputState state, ModifierKey modifiers) {
bool Viewer::onKey(skui::Key key, skui::InputState state, skui::ModifierKey modifiers) {
return fCommands.onKey(key, state, modifiers);
}
bool Viewer::onChar(SkUnichar c, ModifierKey modifiers) {
bool Viewer::onChar(SkUnichar c, skui::ModifierKey modifiers) {
if (fSlides[fCurrentSlide]->onChar(c)) {
fWindow->inval();
return true;

View File

@ -37,11 +37,11 @@ public:
void onBackendCreated() override;
void onPaint(SkSurface*) override;
void onResize(int width, int height) override;
bool onTouch(intptr_t owner, InputState state, float x, float y) override;
bool onMouse(int x, int y, InputState state, ModifierKey modifiers) override;
bool onTouch(intptr_t owner, skui::InputState state, float x, float y) override;
bool onMouse(int x, int y, skui::InputState state, skui::ModifierKey modifiers) override;
void onUIStateChanged(const SkString& stateName, const SkString& stateValue) override;
bool onKey(sk_app::Window::Key key, InputState state, ModifierKey modifiers) override;
bool onChar(SkUnichar c, ModifierKey modifiers) override;
bool onKey(skui::Key key, skui::InputState state, skui::ModifierKey modifiers) override;
bool onChar(SkUnichar c, skui::ModifierKey modifiers) override;
struct SkFontFields {
bool fTypeface = false;