CCPen Class Reference

This provides support for Pressure Sensitive Pen devices. Its job is to keep track of the current pressure of a pen. It will automatically mutate itself into either a Real or Pretend pen, depending on what is availble when it is created. If it is a real pen, then it gets it's pressure from mouse messages. If it is a pretend pen, then the pressure is adjusted using either the keyboard (temporarily Keypad +/-) or by using a joystick. More...

#include <pen.h>

Inheritance diagram for CCPen:

CCObject SimpleCCObject WinTabPressurePen List of all members.

Public Member Functions

 CCPen ()
 CCPen constructor.
 ~CCPen ()
 CCPen destructor.
BOOL IsRealPen ()
BOOL IsPressureOn ()
UINT32 GetPenPressure ()
UINT32 GetPressureMax ()
void SetPressureMode (PressureMode NewMode)
PressureMode GetPressureMode (void)
void SetPressureFromJoystick (WPARAM, LPARAM)
 Set the pretend Pen Pressure from the Joytick Position.
virtual void CheckMouseMessage (UINT32 Message, wxPoint point)
 Checks a mouse message to see if it came from a pen, and if so sets the current pressure value.
virtual void StartStroke (void)
 Informs the Pen class that you are starting a stroke (a drag operation for which you wish to record pressure information).
virtual void EndStroke (void)
 Informs the Pen class that you are completing a stroke (a drag operation for which you recorded pressure information).

Static Public Member Functions

static CCPenInit ()
 Application.LateInit calls this to obtain the default pen object.

Static Public Attributes

static PressureMode DefaultPressureMode = PressureMode_None

Protected Member Functions

virtual BOOL ReadTabletPressureData (void)
 Records the latest pressure info from the pressure sensitive tablet Does nothing if this is not a "real" pen.

Protected Attributes

UINT32 PenPressure
UINT32 PressureMax
BOOL PF_IsPressureOn
BOOL PressureAvailable
PressureMode CurrentPressureMode
HWND hMainframeWnd
wxPoint LastMousePoint

Private Member Functions

 CC_DECLARE_DYNAMIC (CCPen)

Detailed Description

This provides support for Pressure Sensitive Pen devices. Its job is to keep track of the current pressure of a pen. It will automatically mutate itself into either a Real or Pretend pen, depending on what is availble when it is created. If it is a real pen, then it gets it's pressure from mouse messages. If it is a pretend pen, then the pressure is adjusted using either the keyboard (temporarily Keypad +/-) or by using a joystick.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
23/5/94

Definition at line 143 of file pen.h.


Constructor & Destructor Documentation

CCPen::CCPen  ) 
 

CCPen constructor.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
23/5/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-
See also:
-
Returns:
Errors: -

Definition at line 185 of file pen.cpp.

00186 {
00187     PORTNOTETRACE("other","CCPen::CCPen - do nothing");
00188 #ifndef EXCLUDE_FROM_XARALX
00189     // See if it is likely that we'll be able to initialise as a "real" pen
00190     PressureAvailable = FALSE;
00191 
00192     // Initalise member variables
00193     wxWindow           *pMainFrame = GetMainFrame();
00194     ERROR3IF(pMainFrame == NULL, "No main frame window when CCPen initialised");
00195     hMainframeWnd = pMainFrame->m_hWnd;
00196 
00197     PenPressure = 0;
00198     PressureMax = MAXPRESSURE;          // Set the default Maximum Pressure Value
00199 
00200     CurrentPressureMode = DefaultPressureMode;
00201     if (CurrentPressureMode == PressureMode_None)
00202         PenPressure = PressureMax;
00203 
00204     LastMousePoint = CPoint(0,0);
00205 #endif
00206 }

CCPen::~CCPen  ) 
 

CCPen destructor.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
23/5/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

Definition at line 224 of file pen.cpp.

00225 {
00226 }


Member Function Documentation

CCPen::CC_DECLARE_DYNAMIC CCPen   )  [private]
 

void CCPen::CheckMouseMessage UINT32  Message,
wxPoint  point
[virtual]
 

Checks a mouse message to see if it came from a pen, and if so sets the current pressure value.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
15/6/94
Parameters:
Message - WM_MOUSEMOVE if the mouse is moving, or WM_{L/R/M}BUTTONDOWN if [INPUTS] we're starting a drag point - the mouse position
- [OUTPUTS]
Returns:
-

Errors: -

Definition at line 328 of file pen.cpp.

00329 {
00330     PORTNOTETRACE("other","CCPen::CheckMouseMessage - do nothing");
00331 #ifndef EXCLUDE_FROM_XARALX
00332     if (IsRealPen() && CurrentPressureMode == PressureMode_Pen)
00333     {
00334         // Go and check the tablet for new pressure data. If it fails, we will drop through
00335         // to the normal mouse handler - this means if a pen user puts down the pen and
00336         // uses the mouse, we automatically drop back to reading the mouse when we fail to
00337         // recieve pen packets.
00338         if (ReadTabletPressureData())
00339             return;
00340     }
00341 
00342     switch(CurrentPressureMode)
00343     {
00344         case PressureMode_None:
00345             PenPressure = PressureMax;
00346             break;
00347 
00348         case PressureMode_Pen:
00349             // We want to read values from a real pen, but that is unavailable,
00350             // so we drop through to fake something up based on mouse speed.
00351             // NOBREAK
00352 
00353             // 12/8/2000 This has changed, we no longer want to fake pressure at all
00354             PenPressure = PressureMax;
00355             break;
00356         case PressureMode_Speed:
00357             // We've got a fake pen. We use mouse travel speed to generate pressure info
00358             if (Message == WM_MOUSEMOVE)
00359             {
00360                 // Diccon - disabled mouse speed pressure for now
00361                 
00362                 PenPressure = PressureMax / 2 ;// - (INT32)(Speed * (double)PressureMax);
00363 //              PenPressure = (INT32)(Speed * (double)PressureMax);
00364             }
00365             else
00366                 PenPressure = 0;        // Must be mouse down. Init pressure to 0
00367             break;
00368 
00369 
00370         case PressureMode_Direction:
00371             // We've got a fake pen. We use mouse travel direction to generate pressure info
00372             if (Message == WM_MOUSEMOVE)
00373             {
00374                 // Work out direction of travel to do a calligraphic pen
00375                 NormCoord TravelDir(point.x - LastMousePoint.x, point.y - LastMousePoint.y);
00376 
00377                 if (TravelDir.x != 0.0 && TravelDir.y != 0.0)
00378                 {
00379                     TravelDir.Normalise();
00380 
00381                     NormCoord PenAngle(1.0, 1.0);
00382                     PenAngle.Normalise();
00383 
00384                     // Take the dot product of the travel direction and the brush angle (which gives
00385                     // us cos(angle between them)), which makes an excellent pressure (width) value
00386                     // This actually gives us a value between -1 and +1, which we scale into 0..1 range
00387                     double DotProd = TravelDir.DotProduct(PenAngle);
00388                     DotProd = (DotProd + 1.0) / 2.0;
00389 
00390                     PenPressure = (INT32) (DotProd * (double)PressureMax);
00391                 }
00392             }
00393             else
00394                 PenPressure = 0;        // Must be mouse down. Init pressure to 0
00395             break;
00396     }
00397 
00398     // And remember the last mouse position
00399     LastMousePoint = point;
00400 #endif
00401 }

void CCPen::EndStroke void   )  [virtual]
 

Informs the Pen class that you are completing a stroke (a drag operation for which you recorded pressure information).

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/1/97
This function must be called to "cancel" out a call to StartStroke. It should be called in your drag completion routine, and should be called under all "end of drag" circumstances.

Reimplemented in WinTabPressurePen.

Definition at line 272 of file pen.cpp.

00273 {
00274     // Base class does nothing
00275 }

UINT32 CCPen::GetPenPressure  )  [inline]
 

Definition at line 157 of file pen.h.

00157 { return PenPressure; }

UINT32 CCPen::GetPressureMax  )  [inline]
 

Definition at line 158 of file pen.h.

00158 { return PressureMax; }

PressureMode CCPen::GetPressureMode void   )  [inline]
 

Definition at line 164 of file pen.h.

00164 { return(CurrentPressureMode); }

CCPen * CCPen::Init void   )  [static]
 

Application.LateInit calls this to obtain the default pen object.

Author:
Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
Date:
26/9/94
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
Pointer to applications CCPen object, or NULL if failed.

Errors: ->SetError if FALSE Scope: Static

Reimplemented from SimpleCCObject.

Definition at line 152 of file pen.cpp.

00153 {
00154     PORTNOTETRACE("other","CCPen::Init - do nothing");
00155 #ifndef EXCLUDE_FROM_XARALX
00156     // Check the ini file to see what state we're in
00157     if (Camelot.DeclareSection("PenSupport", 4))
00158         Camelot.DeclarePref("PenSupport", "PressureMode", (INT32 *)&DefaultPressureMode, PressureMode_None, PressureMode_MaxEnum);
00159 
00160     // Create a pressure sensitive pen. We create a derived class WinTab pen
00161     // which will call back to the base class if a WinTab device is unavailable.
00162     return(new WinTabPressurePen);
00163 #else
00164     return NULL;
00165 #endif
00166 }

BOOL CCPen::IsPressureOn  )  [inline]
 

Definition at line 156 of file pen.h.

BOOL CCPen::IsRealPen  )  [inline]
 

Definition at line 155 of file pen.h.

00155 { return PressureAvailable; }

BOOL CCPen::ReadTabletPressureData void   )  [protected, virtual]
 

Records the latest pressure info from the pressure sensitive tablet Does nothing if this is not a "real" pen.

Author:
Martin_Donelly (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/1/97
Returns:
TRUE if it read pressure successfully FALSE if it failed - in this case, the caller (base class) will default to calculating a faked pressure value from movement information. (e.g. if you stop getting pen pressure packets, revert to using movement rather than always returning zero!)
Does nothing in the base class.

Reimplemented in WinTabPressurePen.

Definition at line 299 of file pen.cpp.

00300 {
00301     if (!PressureAvailable)
00302         return(FALSE);
00303 
00304     // Base class does nothing
00305     return(FALSE);
00306 }

void CCPen::SetPressureFromJoystick WPARAM  Buttons,
LPARAM  JoyPos
 

Set the pretend Pen Pressure from the Joytick Position.

Author:
Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/6/94
Parameters:
The JoyPos as passed in from the Message Handler (in CCamView) [INPUTS]
- [OUTPUTS]
Returns:
-

Definition at line 418 of file pen.cpp.

00419 {
00420     PORTNOTETRACE("other","CCPen::SetPressureFromJoystick - do nothing");
00421 #ifndef EXCLUDE_FROM_XARALX
00422     if (this->IsRealPen())
00423         return;     // Ignore this call if we are a Real Pen
00424 
00425     if (!(Buttons & JOY_BUTTON1))
00426         return;     // Button1 must be down for the Pressure to be valid
00427 
00428     INT32 Ypos = HIWORD(JoyPos) - (JOYMAX/2);       // Get Y Offset from Joystick Centre
00429 
00430     // Convert the distance from the joystick centre pos, into a value between
00431     // 0 and PressureMax
00432     PenPressure = (Ypos<0 ? -Ypos : Ypos)*PressureMax/(JOYMAX/2);
00433 #endif
00434 }

void CCPen::SetPressureMode PressureMode  NewMode  )  [inline]
 

Definition at line 163 of file pen.h.

void CCPen::StartStroke void   )  [virtual]
 

Informs the Pen class that you are starting a stroke (a drag operation for which you wish to record pressure information).

Author:
Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
Date:
24/1/97
If you do not call this method, then pressure information will be "faked" based on mouse speed/direction information.

It should be called when you start your drag (on button down)

When the stroke finishes, remember to call CCPen::EndStroke

Reimplemented in WinTabPressurePen.

Definition at line 249 of file pen.cpp.

00250 {
00251     CurrentPressureMode = DefaultPressureMode;
00252 }


Member Data Documentation

PressureMode CCPen::CurrentPressureMode [protected]
 

Definition at line 192 of file pen.h.

PressureMode CCPen::DefaultPressureMode = PressureMode_None [static]
 

Definition at line 202 of file pen.h.

HWND CCPen::hMainframeWnd [protected]
 

Definition at line 196 of file pen.h.

wxPoint CCPen::LastMousePoint [protected]
 

Definition at line 199 of file pen.h.

UINT32 CCPen::PenPressure [protected]
 

Definition at line 186 of file pen.h.

BOOL CCPen::PF_IsPressureOn [protected]
 

Definition at line 189 of file pen.h.

BOOL CCPen::PressureAvailable [protected]
 

Definition at line 191 of file pen.h.

UINT32 CCPen::PressureMax [protected]
 

Definition at line 187 of file pen.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:52:10 2007 for Camelot by  doxygen 1.4.4