📄 prgtabtest.cpp
字号:
// PrgTabTest.cpp : implementation of the PrgTabTest class
//
//////////////////////////////////////////////////////////////////////
//
// ** Example using WINTAB for graphics tablets **
//
// Example of how to implement a graphics tablet in an MFC application
// It assumes the tablet controls the mouse pointer so that location
// and button information is obtained from the normal mouse packets.
// To reduce the overhead, only extra information provided by the tablet, is
// captured and processed.
//
// Main Purpose: Capture the pressure level from the tablet pen
// Additions: Other potentially useful tablet information, see 'Information Processed:'
// Excluded: Pointer location and button information provided from mouse driver
//
// Information Processed: (worked out using experimentation)
// Pressure: Just a number representing how hard you are pressing on the tip.
// 0 = Not touching the surface.
// 255 = Maximum pressure (only tested on the Wacom tablet.)
// Altitude: Angle between the pen and the tablet surface. Wacom tablets use
// or this to indicate attitude as well. Positive is when the pen
// Tilt is the normal way up and negative when the pen is upside down with
// the eraser tip towards the surface. See also; the cursor number.
// 0 Tilt would be with the pen laying on the surface, but in practice my
// tablet stopped detecting at an angle of less than 260 degrees.
// 900 Tilt is straight upright, perpendicular to the tablet.
// Twist: Untested, but I think this is a number representing rotating the pen
// between your fingers, or a rotation of a puck about it's point.
// As far as I can tell it is not provided on the Wacom tablet I was using.
// Azimuth: This is the direction the pen is leaning in relation to the pen tip.
// or I refer to this as 'Compass', which I find a more memorable term.
// Compass: 0 = Leaning away from you which I call north, tip nearest to you.
// 900 = East, tip left top end right.
// 1800 = South, tip away from you, top towards you.
// 2700 = West, tip right, top end left.
// 3599 = Nearly back to the north position again.
// Cursor: If the tablet or pen has more than one setting a cursor number
// will be returned. For example; on the Wacom tablet, cursor number
// one (1) is the normal tip and cursor number two (2) is the erase
// tip when the pen is upside down.
//
// Author: John C. Brown, john@clue.demon.co.uk http://www.clue.demon.co.uk
// Date: August 1998
// Copyright: None, use it as you see fit.
// Warranty: None, it's free so it's your problem.
// Test Tablet: Wacom UltraPad A4 (European), ArtZ II 12x12 (US)
//
// Based on: Information found in the Wintab documentation and developer
// resources on the Wacom and the LCS/Telegraphics web sites.
// The latest documentation I have is version 1.1 dated: 9 May 1996.
// ftp://ftp.pointing.com/pointing/Wintab/wt1pt1.zip
// I am only using functions from version 1.0 dated: 13 December 1994.
// ftp://ftp.wacom.com/pub/developer/ibmpc/wintab32.zip
// Required: Wintab library and header files from the developer kit (wtkit124.zip):
// Sources: http://www.pointing.com
// ftp://ftp.pointing.com/pointing/Wintab/wtkit124.zip
// http://www.wacom.com
// ftp://ftp.wacom.com/pub/developer/ibmpc/wtkit124.zip
// ftp://ftp.wacom.de/pub/Others/DEVDISK.ZIP
//
// Documentation: Although WinTab is fully documented, I found it was not clearly
// explained. To work out what most of the terms mean, I had to use
// EXPERIMENTATION using my Wacom tablet, other tablets may differ
// slightly in their function.
//
// Rotation: NOT included in this work. Rotation is new in the WinTab 1.1 specification
// dated 9 May 1996. It is NOT included in the wintab.h header file
// provided in the wintab developer kit version 1.24.
//
// Improvements: If you make any improvements or have tested it on other makes of tablet
// let me know your findings, so I can pass the information on.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "AppTabTest.h"
#include <math.h> // required for example sections only
#include "DocTabTest.h"
#include "PrgTabTest.h"
//////////////////////////////////////////////////////////////////////
//JCB Usage in Visual Studio 97, add the Wintab library and header paths to Project -> Settings:
// All Configurations -> C/C++ -> Additional Include Directories -> '..\wintab\Include\'
// All Configurations -> Link -> Input -> Additional Library Path -> '..\wintab\lib\I386\'
// Add the wintab32.dll to the Projects -> Settings:
// All Configurations -> Link -> Input -> Object/Library modules: -> '..\wintab\lib\I386\wintab32.lib'
// See the #include files in the header for this programme to see further details about wintab.h
//
// Member variables: To identify tablet specific member variables, I have prefixed them
// with t_, for example: t_hTablet.
//
//////////////////////////////////////////////////////////////////////
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//Used for tablet examples
#define FIX_DOUBLE(x) ((double)(INT(x))+((double)FRAC(x)/65536)) // converts FIX32 to double
#define pi 3.14159265359 // or 3.141592653589793
//End of, used for tablet examples
/////////////////////////////////////////////////////////////////////////////
// PrgTabTest
IMPLEMENT_DYNCREATE(PrgTabTest, CView)
BEGIN_MESSAGE_MAP(PrgTabTest, CView)
//{{AFX_MSG_MAP(PrgTabTest)
ON_WM_LBUTTONDOWN()
ON_WM_KILLFOCUS()
ON_WM_SETFOCUS()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
//TABLET: Tablet messages
ON_MESSAGE( WT_PACKET, PrgTabTest::OnTabPacket )
//TABLET: end tablet messages
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// PrgTabTest construction/destruction
PrgTabTest::PrgTabTest()
{
//TABLET: Graphics Tablet
t_hTablet = NULL; // Tablet context handle, required.
t_prsNew = 0;
t_curNew = 0;
t_ortNew.orAzimuth = 0; // 0 = north
t_ortNew.orAltitude = 900; // 900 = vertical
t_ortNew.orTwist = 0;
m_pntMouseLoc = CPoint(0,0); //JCB initialise to zero
//EXAMPLE: extra tablet adjustments, used for this example,
// they may be useful in some other applications
t_bTiltSupport = TRUE; // Table. Is tilt supported
t_dblAltAdjust = 1; // Tablet Altitude zero adjust
t_dblAltFactor = 1; // Tablet Altitude factor
t_dblAziFactor = 1; // Table Azimuth factor
//JCB used for displaying settings
m_strTabletWords = "";
m_strPacketWords = "";
m_strAngleWords = "";
m_strPresWords = "";
m_strButtonWords = "";
m_strPointWords = "";
}
PrgTabTest::~PrgTabTest()
{
if (t_hTablet){
WTClose(t_hTablet);
}
}
BOOL PrgTabTest::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// PrgTabTest drawing
void PrgTabTest::OnDraw(CDC* pDC)
{
DocTabTest* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// draw code for native data here
//JCB text metrics
// get text height
int nTextHeight = 0;
int nTextGap = 0;
int nTextRow = 0;
TEXTMETRIC textMetrics;
if(pDC->GetTextMetrics(&textMetrics)){
nTextHeight = textMetrics.tmHeight;
}
nTextGap = 0;
nTextRow = nTextHeight + nTextGap;
pDC->TextOut(0,0, m_strPointWords);
pDC->TextOut(0,(1 * nTextRow), m_strButtonWords);
pDC->TextOut(0,(2 * nTextRow), m_strPresWords);
pDC->TextOut(0,(3 * nTextRow), m_strAngleWords);
pDC->TextOut(0,(4 * nTextRow), m_strTabletWords);
pDC->TextOut(0,(5 * nTextRow), m_strTiltWords);
pDC->TextOut(0,(6 * nTextRow), m_strPacketWords);
RepresentPen(pDC);
}
/////////////////////////////////////////////////////////////////////////////
// PrgTabTest printing
BOOL PrgTabTest::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void PrgTabTest::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void PrgTabTest::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// PrgTabTest diagnostics
#ifdef _DEBUG
void PrgTabTest::AssertValid() const
{
CView::AssertValid();
}
void PrgTabTest::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
DocTabTest* PrgTabTest::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(DocTabTest)));
return (DocTabTest*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// PrgTabTest message handlers
void PrgTabTest::OnLButtonDown(UINT nFlags, CPoint point)
{
//JCB
m_strButtonWords = "Left Button Down:";
Invalidate(); //required for mouse only
CView::OnLButtonDown(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -