mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-06 12:39:57 +00:00
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).
This commit is contained in:
parent
e723426214
commit
1c94dda072
@ -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)
|
||||
|
@ -445,7 +445,6 @@ target_link_libraries(app-lib
|
||||
flic-lib
|
||||
gfx-lib
|
||||
net-lib
|
||||
pen-lib
|
||||
render-lib
|
||||
script-lib
|
||||
she
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include "she/common/freetype_font.h"
|
||||
#include "she/common/sprite_sheet_font.h"
|
||||
#include "she/system.h"
|
||||
|
||||
namespace she {
|
||||
|
||||
|
@ -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__
|
||||
|
@ -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)
|
||||
|
96
src/she/win/pen.cpp
Normal file
96
src/she/win/pen.cpp
Normal file
@ -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
|
34
src/she/win/pen.h
Normal file
34
src/she/win/pen.h
Normal file
@ -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
|
31
src/she/win/system.h
Normal file
31
src/she/win/system.h
Normal file
@ -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
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user