[aseprite] 36/128: Merge pen library into she library
Tobias Hansen
thansen at moszumanska.debian.org
Mon May 9 21:24:20 UTC 2016
This is an automated email from the git hooks/post-receive script.
thansen pushed a commit to branch master
in repository aseprite.
commit 1c94dda072ffb23ffa0d22652c26300df663f081
Author: David Capello <davidcapello at gmail.com>
Date: Wed Apr 20 12:48:49 2016 -0300
Merge pen library into she library
This is the first step to add pen information to mouse events
(e.g. to known if a event came from the eraser or the regular tip).
---
src/CMakeLists.txt | 1 -
src/app/CMakeLists.txt | 1 -
src/app/app.cpp | 4 --
src/she/CMakeLists.txt | 1 +
src/she/common/system.h | 1 +
src/she/skia/she.cpp | 2 -
src/she/skia/skia_system.h | 7 +++-
src/she/win/pen.cpp | 96 ++++++++++++++++++++++++++++++++++++++++++++++
src/she/win/pen.h | 34 ++++++++++++++++
src/she/win/system.h | 31 +++++++++++++++
src/she/win/window.h | 15 +++++++-
11 files changed, 183 insertions(+), 10 deletions(-)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 03aa0fd..afc8714 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -102,7 +102,6 @@ add_subdirectory(flic)
add_subdirectory(gen)
add_subdirectory(gfx)
add_subdirectory(net)
-add_subdirectory(pen)
add_subdirectory(render)
add_subdirectory(script)
add_subdirectory(she)
diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt
index 6688700..74e2e66 100644
--- a/src/app/CMakeLists.txt
+++ b/src/app/CMakeLists.txt
@@ -445,7 +445,6 @@ target_link_libraries(app-lib
flic-lib
gfx-lib
net-lib
- pen-lib
render-lib
script-lib
she
diff --git a/src/app/app.cpp b/src/app/app.cpp
index 97a5fce..dfe0e45 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -67,7 +67,6 @@
#include "doc/palette.h"
#include "doc/site.h"
#include "doc/sprite.h"
-#include "pen/pen.h"
#include "render/render.h"
#include "script/engine_delegate.h"
#include "she/display.h"
@@ -666,9 +665,6 @@ void App::run()
{
// Run the GUI
if (isGui()) {
- // Initialize Wacom tablet API
- pen::PenAPI pen(she::instance()->defaultDisplay()->nativeHandle());
-
// Initialize Steam API
#ifdef ENABLE_STEAM
steam::SteamAPI steam;
diff --git a/src/she/CMakeLists.txt b/src/she/CMakeLists.txt
index 727c39b..cddf5bc 100644
--- a/src/she/CMakeLists.txt
+++ b/src/she/CMakeLists.txt
@@ -187,6 +187,7 @@ if(USE_SKIA_BACKEND)
if(WIN32)
list(APPEND SHE_SOURCES
skia/skia_window_win.cpp
+ win/pen.cpp
win/vk.cpp
win/window_dde.cpp)
elseif(APPLE)
diff --git a/src/she/common/system.h b/src/she/common/system.h
index 273d445..f03a0ce 100644
--- a/src/she/common/system.h
+++ b/src/she/common/system.h
@@ -24,6 +24,7 @@
#include "she/common/freetype_font.h"
#include "she/common/sprite_sheet_font.h"
+#include "she/system.h"
namespace she {
diff --git a/src/she/skia/she.cpp b/src/she/skia/she.cpp
index e45ac5d..833a0da 100644
--- a/src/she/skia/she.cpp
+++ b/src/she/skia/she.cpp
@@ -13,8 +13,6 @@
#include "gfx/size.h"
#include "she/she.h"
-#include "she/common/system.h"
-
#include "she/skia/skia_system.h"
#if __APPLE__
diff --git a/src/she/skia/skia_system.h b/src/she/skia/skia_system.h
index a8a6d61..e40e4d6 100644
--- a/src/she/skia/skia_system.h
+++ b/src/she/skia/skia_system.h
@@ -15,23 +15,28 @@
#include "SkPixelRef.h"
#include "SkStream.h"
+#include "she/common/system.h"
#include "she/skia/skia_display.h"
#include "she/skia/skia_surface.h"
#ifdef _WIN32
#include "she/win/event_queue.h"
+ #include "she/win/system.h"
+ #define SkiaSystemBase WindowSystem
#elif __APPLE__
#include "she/osx/app.h"
#include "she/osx/event_queue.h"
+ #define SkiaSystemBase CommonSystem
#else
#include "she/x11/event_queue.h"
+ #define SkiaSystemBase CommonSystem
#endif
namespace she {
EventQueueImpl g_queue;
-class SkiaSystem : public CommonSystem {
+class SkiaSystem : public SkiaSystemBase {
public:
SkiaSystem()
: m_defaultDisplay(nullptr)
diff --git a/src/she/win/pen.cpp b/src/she/win/pen.cpp
new file mode 100644
index 0000000..343d08c
--- /dev/null
+++ b/src/she/win/pen.cpp
@@ -0,0 +1,96 @@
+// SHE library
+// Copyright (C) 2016 David Capello
+//
+// This file is released under the terms of the MIT license.
+// Read LICENSE.txt for more information.
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "she/win/pen.h"
+
+#include "base/debug.h"
+#include "base/fs.h"
+#include "base/log.h"
+#include "base/path.h"
+#include "base/string.h"
+
+typedef UINT (API* WTInfoW_Func)(UINT, UINT, LPVOID);
+typedef HCTX (API* WTOpenW_Func)(HWND, LPLOGCONTEXTW, BOOL);
+typedef BOOL (API* WTClose_Func)(HCTX);
+
+namespace she {
+
+static WTInfoW_Func WTInfo;
+static WTOpenW_Func WTOpen;
+static WTClose_Func WTClose;
+
+PenAPI::PenAPI()
+ : m_wintabLib(nullptr)
+{
+}
+
+PenAPI::~PenAPI()
+{
+ if (!m_wintabLib)
+ return;
+
+ base::unload_dll(m_wintabLib);
+ m_wintabLib = nullptr;
+}
+
+HCTX PenAPI::attachDisplay(HWND hwnd)
+{
+ if (!m_wintabLib && !loadWintab())
+ return nullptr;
+
+ LOGCONTEXTW logctx;
+ memset(&logctx, 0, sizeof(LOGCONTEXTW));
+ logctx.lcOptions |= CXO_SYSTEM;
+ UINT infoRes = WTInfo(WTI_DEFSYSCTX, 0, &logctx);
+ ASSERT(infoRes == sizeof(LOGCONTEXTW));
+ ASSERT(logctx.lcOptions & CXO_SYSTEM);
+ logctx.lcOptions |= CXO_SYSTEM;
+ HCTX ctx = WTOpen(hwnd, &logctx, TRUE);
+ if (!ctx) {
+ LOG("Error attaching pen to display\n");
+ return nullptr;
+ }
+
+ LOG("Pen attached to display\n");
+ return ctx;
+}
+
+void PenAPI::detachDisplay(HCTX ctx)
+{
+ if (ctx) {
+ ASSERT(m_wintabLib);
+ LOG("Pen detached from window\n");
+ WTClose(ctx);
+ }
+}
+
+bool PenAPI::loadWintab()
+{
+ ASSERT(!m_wintabLib);
+
+ m_wintabLib = base::load_dll("wintab32.dll");
+ if (!m_wintabLib) {
+ LOG("wintab32.dll is not present\n");
+ return false;
+ }
+
+ WTInfo = base::get_dll_proc<WTInfoW_Func>(m_wintabLib, "WTInfoW");
+ WTOpen = base::get_dll_proc<WTOpenW_Func>(m_wintabLib, "WTOpenW");
+ WTClose = base::get_dll_proc<WTClose_Func>(m_wintabLib, "WTClose");
+ if (!WTInfo || !WTOpen || !WTClose) {
+ LOG("wintab32.dll does not contain all required functions\n");
+ return false;
+ }
+
+ LOG("Pen initialized\n");
+ return true;
+}
+
+} // namespace she
diff --git a/src/she/win/pen.h b/src/she/win/pen.h
new file mode 100644
index 0000000..d9ac9f6
--- /dev/null
+++ b/src/she/win/pen.h
@@ -0,0 +1,34 @@
+// SHE library
+// Copyright (C) 2016 David Capello
+//
+// This file is released under the terms of the MIT license.
+// Read LICENSE.txt for more information.
+
+#ifndef SHE_WIN_PEN_H_INCLUDED
+#define SHE_WIN_PEN_H_INCLUDED
+#pragma once
+
+#include "base/dll.h"
+
+#include <windows.h>
+#include "wacom/wintab.h"
+
+namespace she {
+
+ class PenAPI {
+ public:
+ PenAPI();
+ ~PenAPI();
+
+ HCTX attachDisplay(HWND hwnd);
+ void detachDisplay(HCTX ctx);
+
+ private:
+ bool loadWintab();
+
+ base::dll m_wintabLib;
+ };
+
+} // namespace she
+
+#endif
diff --git a/src/she/win/system.h b/src/she/win/system.h
new file mode 100644
index 0000000..4841412
--- /dev/null
+++ b/src/she/win/system.h
@@ -0,0 +1,31 @@
+// SHE library
+// Copyright (C) 2012-2016 David Capello
+//
+// This file is released under the terms of the MIT license.
+// Read LICENSE.txt for more information.
+
+#ifndef SHE_WIN_SYSTEM_H
+#define SHE_WIN_SYSTEM_H
+#pragma once
+
+#include "she/common/system.h"
+#include "she/win/pen.h"
+
+namespace she {
+
+class WindowSystem : public CommonSystem {
+public:
+ WindowSystem() { }
+ ~WindowSystem() { }
+
+ PenAPI& penApi() {
+ return m_penApi;
+ }
+
+private:
+ PenAPI m_penApi;
+};
+
+} // namespace she
+
+#endif
diff --git a/src/she/win/window.h b/src/she/win/window.h
index be29adf..216ccd5 100644
--- a/src/she/win/window.h
+++ b/src/she/win/window.h
@@ -19,6 +19,7 @@
#include "she/event.h"
#include "she/keys.h"
#include "she/native_cursor.h"
+#include "she/win/system.h"
#include "she/win/window_dde.h"
#ifndef WM_MOUSEHWHEEL
@@ -43,13 +44,24 @@ namespace she {
, m_captureMouse(false) {
registerClass();
m_hwnd = createHwnd(this, width, height);
- m_hcursor = NULL;
+ m_hcursor = nullptr;
+ m_hpenctx = nullptr;
m_scale = scale;
// This flag is used to avoid calling T::resizeImpl() when we
// add the scrollbars to the window. (As the T type could not be
// fully initialized yet.)
m_isCreated = true;
+
+ // Attach Wacom context
+ m_hpenctx = static_cast<WindowSystem*>(she::instance())
+ ->penApi().attachDisplay(m_hwnd);
+ }
+
+ ~WinWindow() {
+ if (m_hpenctx)
+ static_cast<WindowSystem*>(she::instance())
+ ->penApi().detachDisplay(m_hpenctx);
}
void queueEvent(Event& ev) {
@@ -667,6 +679,7 @@ namespace she {
mutable HWND m_hwnd;
HCURSOR m_hcursor;
+ HCTX m_hpenctx; // Wacom Pen context
gfx::Size m_clientSize;
gfx::Size m_restoredSize;
int m_scale;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git
More information about the Pkg-games-commits
mailing list