Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » Using Pen with U++
Using Pen with U++ [message #56390] Wed, 03 March 2021 16:13 Go to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi,

I just got a Wacom Intuos S (pen tablet). I'm planning on supporting using these devices with my software. Using the pen in place of the mouse works mostly as expected.

However, I would like to read the pen pressure in MouseMove(), (and possibly tilt/rotation some day too):

	POINTER_INFO pi;
	POINTER_PEN_INFO ppi;
	
	UINT32 pressure=0;
	
	if(GetPointerInfo(GET_POINTERID_WPARAM(wParam), &pi)) {
	  if(pi.pointerType == PT_PEN) {
	    UINT32 ppid = pi.pointerId;
	    if(GetPointerPenInfo(ppid, &ppi)) pressure=ppi.pressure;
	  }
	}


,but I can't, since I cannot access wParam.

Would it be much trouble to add support inside CtrlCore for getting pen pressure for current MouseMove()?

Unfortunately GetPointerInfo() and GetPointerPenInfo() are only available in Windows 8 and later, so some conditioning is required.

Best regards,

Tom

[Updated on: Wed, 03 March 2021 16:14]

Report message to a moderator

Re: Using Pen with U++ [message #56391 is a reply to message #56390] Wed, 03 March 2021 17:06 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Tom1 wrote on Wed, 03 March 2021 16:13
Hi,

I just got a Wacom Intuos S (pen tablet). I'm planning on supporting using these devices with my software. Using the pen in place of the mouse works mostly as expected.

However, I would like to read the pen pressure in MouseMove(), (and possibly tilt/rotation some day too):

	POINTER_INFO pi;
	POINTER_PEN_INFO ppi;
	
	UINT32 pressure=0;
	
	if(GetPointerInfo(GET_POINTERID_WPARAM(wParam), &pi)) {
	  if(pi.pointerType == PT_PEN) {
	    UINT32 ppid = pi.pointerId;
	    if(GetPointerPenInfo(ppid, &ppi)) pressure=ppi.pressure;
	  }
	}


,but I can't, since I cannot access wParam.

Would it be much trouble to add support inside CtrlCore for getting pen pressure for current MouseMove()?

Unfortunately GetPointerInfo() and GetPointerPenInfo() are only available in Windows 8 and later, so some conditioning is required.

Best regards,

Tom


Sure and you can code around Windows 8 stuff (we do it here and there already, you just need to load the function pointer in the code).

Going to search for cheap tablet Smile

Mirek
Re: Using Pen with U++ [message #56392 is a reply to message #56391] Wed, 03 March 2021 20:40 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi Mirek,

Thanks, sounds great!

I was too frugal to get one with tilt and/or rotation as I don't really need them at this time. So I can only test the pressure part here.

I wonder if Gdk support is straight forward...

Best regards,

Tom
Re: Using Pen with U++ [message #56409 is a reply to message #56392] Tue, 09 March 2021 12:04 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Should be implemented in windows. This works on my computer:

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

struct MyApp : TopWindow {
	Point pos;
	
	Vector<Vector<Tuple<double, Pointf>>> drawing;
	
	virtual void LeftDown(Point p, dword)
	{
		if(IsPointerPen())
			drawing.Add().Add(MakeTuple(GetPenPressure(), p));
		Refresh();
	}

	virtual void MouseMove(Point p, dword keyflags) {
		pos = p;
		if(IsPointerPen() && drawing.GetCount())
			drawing.Top().Add(MakeTuple(GetPenPressure(), p));
		Refresh();
	}
	
	virtual void Paint(Draw& w0)
	{
		DrawPainter w(w0, GetSize());
		w.Clear(SColorPaper());
		
		w.LineCap(LINECAP_ROUND);
		for(const auto& stroke : drawing)
			if(stroke.GetCount())
				for(int i = 0; i < stroke.GetCount() - 1; i++) {
					w.Move(stroke[i].b);
					w.Line(stroke[i + 1].b);
					w.Stroke(DPI(20) * stroke[i].a, Black());
				}
		
		int fcy = GetStdFontCy();
		int y = 10;
		auto Text = [&] (const String& text) {
			w.DrawText(10, y, text);
			y += fcy;
		};
		Text(AsString(pos));
		Text(String() << "Pen: " << IsPointerPen());
		Text(String() << "Pressure: " << GetPenPressure());
		Text(String() << "Rotation: " << GetPenRotation());
		Text(String() << "Tilt: " << GetPenTilt());
		Text(String() << "Barrel: " << IsPenBarrelPressed());
		Text(String() << "Inverted: " << IsPenInverted());
		Text(String() << "Eraser: " << IsPenInverted());
		Refresh();
	}
};

GUI_APP_MAIN
{
	MyApp().Run();
}


Cheap tablet I have bought does not have tilt/rotation support so I cannot test it, but the code is quite straightforward so there is a good chance it will work - it is good that you have that HW in yours Smile

These changes should not break Win7 compatibility, once again would be nice if you tested that.
Re: Using Pen with U++ [message #56410 is a reply to message #56409] Tue, 09 March 2021 13:10 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi Mirek,

Thanks for getting this going! Unfortunately, my hardware returns false for IsPointerPen(). Based on RDUMPs I tried, it never even visits this code in Ctrl::WindowProc() :
	case WM_POINTERDOWN:
	case WM_POINTERUPDATE:
	case WM_POINTERUP:
		...


I will try to dig in further to figure out what's going on...

As for Windows 7, I have none left... I hope someone around here still does.

Best regards,

Tom
Re: Using Pen with U++ [message #56411 is a reply to message #56410] Tue, 09 March 2021 13:27 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Tom1 wrote on Tue, 09 March 2021 13:10
Hi Mirek,

Thanks for getting this going! Unfortunately, my hardware returns false for IsPointerPen(). Based on RDUMPs I tried, it never even visits this code in Ctrl::WindowProc() :
	case WM_POINTERDOWN:
	case WM_POINTERUPDATE:
	case WM_POINTERUP:
		...


I will try to dig in further to figure out what's going on...

As for Windows 7, I have none left... I hope someone around here still does.

Best regards,

Tom


Do you have proper drivers installed? I have found it is not quite easy to get the pen working...

Mirek
Re: Using Pen with U++ [message #56412 is a reply to message #56411] Tue, 09 March 2021 13:41 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi,

Yes, drivers are the current WACOM drivers. The pen does show pressure on Wacom Tablet Properties -control app.

Now I found that I had to enable 'Use Windows Ink' checkbox on Wacom Tablet Properties / Mapping page. Otherwise there will be no WM_POINTER... messages at all. However, this is unfortunate, since this causes drawing to start with a couple of centimeters long straight line before I can draw any curves. Anyway, this gets the IsPointerPen() true!

I also found that:

						if(ppi.penMask & PEN_MASK_ROTATION)
							pen_pressure = ppi.rotation * M_2PI / 360;


should be

						if(ppi.penMask & PEN_MASK_ROTATION)
							pen_rotation = ppi.rotation * M_2PI / 360;


Then the thickness works based on pressure.

Best regards,

Tom
Re: Using Pen with U++ [message #56413 is a reply to message #56412] Tue, 09 March 2021 13:47 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Tom1 wrote on Tue, 09 March 2021 13:41
Hi,

Yes, drivers are the current WACOM drivers. The pen does show pressure on Wacom Tablet Properties -control app.

Now I found that I had to enable 'Use Windows Ink' checkbox on Wacom Tablet Properties / Mapping page. Otherwise there will be no WM_POINTER... messages at all. However, this is unfortunate, since this causes drawing to start with a couple of centimeters long straight line before I can draw any curves. Anyway, this gets the IsPointerPen() true!

I also found that:

						if(ppi.penMask & PEN_MASK_ROTATION)
							pen_pressure = ppi.rotation * M_2PI / 360;


should be

						if(ppi.penMask & PEN_MASK_ROTATION)
							pen_rotation = ppi.rotation * M_2PI / 360;


Then the thickness works based on pressure.

Best regards,

Tom


Thanks, thats a typo, fixed.
Re: Using Pen with U++ [message #56415 is a reply to message #56413] Tue, 09 March 2021 13:59 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Mirek, did you get a Wacom or something else?

When I start drawing with the pen (and using 'Use Windows Ink' mode), Windows first draws a circle around the pointer and then only after I have moved about two centimeters, it starts drawing... with the first two centimeters of straight line and only thereafter it accurately follows the pen.

I do not know, but this feels like a Windows Ink behavior. Anyway, it makes freehand drawing impossible. I need to figure out how to get rid of this pre-processing of pen movements.

Best regards,

Tom
Re: Using Pen with U++ [message #56416 is a reply to message #56415] Tue, 09 March 2021 14:18 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi,

I can now see that even when using 'Use Windows Ink' -mode, Microsoft's own 'Snip and Sketch' tool can draw tiny features without any 2 cm straight lines starters. There must be something that can be used to turn off that pre-processing programmatically.

Best regards,

Tom
Re: Using Pen with U++ [message #56417 is a reply to message #56415] Tue, 09 March 2021 14:37 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Tom1 wrote on Tue, 09 March 2021 13:59
Mirek, did you get a Wacom or something else?

When I start drawing with the pen (and using 'Use Windows Ink' mode), Windows first draws a circle around the pointer and then only after I have moved about two centimeters, it starts drawing... with the first two centimeters of straight line and only thereafter it accurately follows the pen.

I do not know, but this feels like a Windows Ink behavior. Anyway, it makes freehand drawing impossible. I need to figure out how to get rid of this pre-processing of pen movements.

Best regards,

Tom


XP-PEN. Knowing that you have Wacom, wanted to diversify...
Re: Using Pen with U++ [message #56418 is a reply to message #56417] Tue, 09 March 2021 14:39 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Are you testing with my code? Because I can only speak about that one and with xp-pen, it works fine with my example...

Mirek
Re: Using Pen with U++ [message #56419 is a reply to message #56418] Tue, 09 March 2021 15:07 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Diversifying input devices sounds a good idea. Especially now that they indeed work differently.

And yes, I'm using your testing code, since diversifying there does not sound too smart...

-

Anyway, now I found that I cannot get any WM_MOUSEMOVE from the first 2 cm on screen when using Wacom with Use Windows Ink enabled. However, all the moves right from start end up in WM_POINTERUPDATE. Now this means that we need to add the following code to WM_POINTERUPDATE for pen and disable it in WM_MOUSEMOVE for pen:

	DoMouse(MOUSEMOVE, Point(lParam));
	DoCursorShape();


However, there's a slight problem here. The lParam coordinates are for the screen not window, so it needs some translation. I don't know yet how to do it...

Best regards,

Tom
Re: Using Pen with U++ [message #56420 is a reply to message #56419] Tue, 09 March 2021 15:59 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Tom1 wrote on Tue, 09 March 2021 15:07
Diversifying input devices sounds a good idea. Especially now that they indeed work differently.

And yes, I'm using your testing code, since diversifying there does not sound too smart...

-

Anyway, now I found that I cannot get any WM_MOUSEMOVE from the first 2 cm on screen when using Wacom with Use Windows Ink enabled. However, all the moves right from start end up in WM_POINTERUPDATE. Now this means that we need to add the following code to WM_POINTERUPDATE for pen and disable it in WM_MOUSEMOVE for pen:


Disable part seems quite hard to do...

Mirek
Re: Using Pen with U++ [message #56421 is a reply to message #56420] Tue, 09 March 2021 16:56 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
How about this approach using EnableMouseInPointer() as follows?
LRESULT Ctrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {
	GuiLock __;
	eventid++;
//	LLOG("Ctrl::WindowProc(" << message << ") in " << ::Name(this) << ", focus " << (void *)::GetFocus());
	Ptr<Ctrl> _this = this;
	HWND hwnd = GetHWND();
	
	ONCELOCK {
		EnableMouseInPointer(true); // #1 - enable mouse in WM_POINTER* messages
	};
	
	switch(message) {
	case WM_POINTERDOWN:
	case WM_POINTERUPDATE:
	case WM_POINTERUP:
		{

			POINT p = Point(lParam);
			ScreenToClient(hwnd, &p);

			pen = false;
			pen_pressure = pen_rotation = Null;
			pen_tilt = Null;
			pen_eraser = false;
			pen_barrel = false;
			pen_inverted = false;
			
			static BOOL (WINAPI *GetPointerType)(UINT32 pointerId, POINTER_INPUT_TYPE *pointerType);
			static BOOL (WINAPI *GetPointerInfo)(UINT32 pointerId, POINTER_INFO *pointerInfo);
			static BOOL (WINAPI *GetPointerPenInfo)(UINT32 pointerId, POINTER_PEN_INFO *penInfo);
			static BOOL (WINAPI *GetPointerTouchInfo)(UINT32 pointerId, POINTER_TOUCH_INFO *touchInfo);

			ONCELOCK {
				DllFn(GetPointerType, "User32.dll", "GetPointerType");
				DllFn(GetPointerInfo, "User32.dll", "GetPointerInfo");
				DllFn(GetPointerPenInfo, "User32.dll", "GetPointerPenInfo");
				DllFn(GetPointerTouchInfo, "User32.dll", "GetPointerTouchInfo");
			};
			
			POINTER_INPUT_TYPE pointerType;
			

			UINT32 pointerId = GET_POINTERID_WPARAM(wParam);
			if(GetPointerType && GetPointerPenInfo && GetPointerType(pointerId, &pointerType)) {
				switch(pointerType){
					case PT_PEN:{
						POINTER_PEN_INFO ppi;
						if(GetPointerPenInfo(pointerId, &ppi)) {
							pen = true;
							if(ppi.penFlags & PEN_FLAG_BARREL)
								pen_barrel = true;
							if(ppi.penFlags & PEN_FLAG_INVERTED)
								pen_inverted = true;
							if(ppi.penFlags & PEN_FLAG_ERASER)
								pen_eraser = true;
							if(ppi.penMask & PEN_MASK_PRESSURE)
								pen_pressure = ppi.pressure / 1024.0;
							if(ppi.penMask & PEN_MASK_ROTATION)
								pen_rotation = ppi.rotation * M_2PI / 360;
							if(ppi.penMask & PEN_MASK_TILT_X)
								pen_tilt.x = ppi.tiltX * M_2PI / 360;
							if(ppi.penMask & PEN_MASK_TILT_Y)
								pen_tilt.y = ppi.tiltY * M_2PI / 360;
							
						}
						break;
					}
					case PT_TOUCH:{
						POINTER_TOUCH_INFO pti;
						if(GetPointerTouchInfo(pointerId, &pti)) {
							// Add something touch specific here some day maybe...
						}
						break;
					}
					default:{
						POINTER_INFO pi;
						if(GetPointerInfo(pointerId, &pi)) {
						}
						break;
					}
				}

				if(_this) switch(message){
					case WM_POINTERDOWN:
						ClickActivateWnd();
						DoMouse(LEFTDOWN, Point(p), 0);
						PostInput();
						break;
					case WM_POINTERUP:
						DoMouse(LEFTUP, Point(p), 0);
						PostInput();
						break;
					case WM_POINTERUPDATE:
						DoMouse(MOUSEMOVE, Point(p));
						DoCursorShape();
						break;
				}
				
			}
		}
		break;
	case WM_POINTERLEAVE:
		pen = false;
		break;


Further more, this requires disabling WM_LEFTUP, WM_LEFTDOWN and WM_MOUSEMOVE as they now come in as WM_POINTER* messages.

IMPORTANT WARNING: I have not replicated their function completely in WM_POINTER above as I do not quite understand all the finer details there. Also, I'm worried about breaking everything, so I'll just throw this in 'as is' for you to consider...

Oh and yes, this fixes the 2 cm straight line start issue... Smile

Best regards,

Tom

EDIT: EnableMouseInPointer() is available on Windows8 and above only, so it needs to be loaded in a similar way as the rest of the Pointer -functions.

[Updated on: Tue, 09 March 2021 17:45]

Report message to a moderator

Re: Using Pen with U++ [message #56422 is a reply to message #56421] Tue, 09 March 2021 17:48 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Tom1 wrote on Tue, 09 March 2021 16:56
How about this approach using EnableMouseInPointer() as follows?
LRESULT Ctrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {
	GuiLock __;
	eventid++;
//	LLOG("Ctrl::WindowProc(" << message << ") in " << ::Name(this) << ", focus " << (void *)::GetFocus());
	Ptr<Ctrl> _this = this;
	HWND hwnd = GetHWND();
	
	ONCELOCK {
		EnableMouseInPointer(true); // #1 - enable mouse in WM_POINTER* messages
	};
	
	switch(message) {
	case WM_POINTERDOWN:
	case WM_POINTERUPDATE:
	case WM_POINTERUP:
		{

			POINT p = Point(lParam);
			ScreenToClient(hwnd, &p);

			pen = false;
			pen_pressure = pen_rotation = Null;
			pen_tilt = Null;
			pen_eraser = false;
			pen_barrel = false;
			pen_inverted = false;
			
			static BOOL (WINAPI *GetPointerType)(UINT32 pointerId, POINTER_INPUT_TYPE *pointerType);
			static BOOL (WINAPI *GetPointerInfo)(UINT32 pointerId, POINTER_INFO *pointerInfo);
			static BOOL (WINAPI *GetPointerPenInfo)(UINT32 pointerId, POINTER_PEN_INFO *penInfo);
			static BOOL (WINAPI *GetPointerTouchInfo)(UINT32 pointerId, POINTER_TOUCH_INFO *touchInfo);

			ONCELOCK {
				DllFn(GetPointerType, "User32.dll", "GetPointerType");
				DllFn(GetPointerInfo, "User32.dll", "GetPointerInfo");
				DllFn(GetPointerPenInfo, "User32.dll", "GetPointerPenInfo");
				DllFn(GetPointerTouchInfo, "User32.dll", "GetPointerTouchInfo");
			};
			
			POINTER_INPUT_TYPE pointerType;
			

			UINT32 pointerId = GET_POINTERID_WPARAM(wParam);
			if(GetPointerType && GetPointerPenInfo && GetPointerType(pointerId, &pointerType)) {
				switch(pointerType){
					case PT_PEN:{
						POINTER_PEN_INFO ppi;
						if(GetPointerPenInfo(pointerId, &ppi)) {
							pen = true;
							if(ppi.penFlags & PEN_FLAG_BARREL)
								pen_barrel = true;
							if(ppi.penFlags & PEN_FLAG_INVERTED)
								pen_inverted = true;
							if(ppi.penFlags & PEN_FLAG_ERASER)
								pen_eraser = true;
							if(ppi.penMask & PEN_MASK_PRESSURE)
								pen_pressure = ppi.pressure / 1024.0;
							if(ppi.penMask & PEN_MASK_ROTATION)
								pen_rotation = ppi.rotation * M_2PI / 360;
							if(ppi.penMask & PEN_MASK_TILT_X)
								pen_tilt.x = ppi.tiltX * M_2PI / 360;
							if(ppi.penMask & PEN_MASK_TILT_Y)
								pen_tilt.y = ppi.tiltY * M_2PI / 360;
							
						}
						break;
					}
					case PT_TOUCH:{
						POINTER_TOUCH_INFO pti;
						if(GetPointerTouchInfo(pointerId, &pti)) {
							// Add something touch specific here some day maybe...
						}
						break;
					}
					default:{
						POINTER_INFO pi;
						if(GetPointerInfo(pointerId, &pi)) {
						}
						break;
					}
				}

				if(_this) switch(message){
					case WM_POINTERDOWN:
						ClickActivateWnd();
						DoMouse(LEFTDOWN, Point(p), 0);
						PostInput();
						break;
					case WM_POINTERUP:
						DoMouse(LEFTUP, Point(p), 0);
						PostInput();
						break;
					case WM_POINTERUPDATE:
						DoMouse(MOUSEMOVE, Point(p));
						DoCursorShape();
						break;
				}
				
			}
		}
		break;
	case WM_POINTERLEAVE:
		pen = false;
		break;


Further more, this requires disabling WM_LEFTUP, WM_LEFTDOWN and WM_MOUSEMOVE as they now come in as WM_POINTER* messages.

IMPORTANT WARNING: I have not replicated their function completely in WM_POINTER above as I do not quite understand all the finer details there. Also, I'm worried about breaking everything, so I'll just throw this in 'as is' for you to consider...

Oh and yes, this fixes the 2 cm straight line start issue... Smile

Best regards,

Tom

EDIT: EnableMouseInPointer() is available on Windows8 and above only, so it needs to be loaded in a similar way as the rest of the Pointer -functions.


Looks good. Will try tommorow.
Re: Using Pen with U++ [message #56423 is a reply to message #56422] Tue, 09 March 2021 18:14 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
OK, good! But please try this one instead, as it takes into account the Win8 thing and also adds conditional blocking of WM_MOUSEMOVE, WM_LBUTTONUP, WM_LBUTTONDOWN:

LRESULT Ctrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {
	GuiLock __;
	eventid++;
//	LLOG("Ctrl::WindowProc(" << message << ") in " << ::Name(this) << ", focus " << (void *)::GetFocus());
	Ptr<Ctrl> _this = this;
	HWND hwnd = GetHWND();
	
	static bool disableOldWMs=false; // When true, blocks out original WM_MOUSEMOVE, WM_LBUTTONUP, WM_LBUTTONDOWN

		
	switch(message) {
	case WM_POINTERDOWN:
	case WM_POINTERUPDATE:
	case WM_POINTERUP:
		{

			POINT p = Point(lParam);
			ScreenToClient(hwnd, &p);

			pen = false;
			pen_pressure = pen_rotation = Null;
			pen_tilt = Null;
			pen_eraser = false;
			pen_barrel = false;
			pen_inverted = false;
			
			static BOOL (WINAPI *EnableMouseInPointer)(WINBOOL fEnable);
			static BOOL (WINAPI *GetPointerType)(UINT32 pointerId, POINTER_INPUT_TYPE *pointerType);
			static BOOL (WINAPI *GetPointerInfo)(UINT32 pointerId, POINTER_INFO *pointerInfo);
			static BOOL (WINAPI *GetPointerPenInfo)(UINT32 pointerId, POINTER_PEN_INFO *penInfo);
			static BOOL (WINAPI *GetPointerTouchInfo)(UINT32 pointerId, POINTER_TOUCH_INFO *touchInfo);

			ONCELOCK {
				DllFn(EnableMouseInPointer, "User32.dll", "EnableMouseInPointer");
				if(EnableMouseInPointer && EnableMouseInPointer(true)) disableOldWMs=true; // Switching over to WM_POINTER* functions for mouse
				
				DllFn(GetPointerType, "User32.dll", "GetPointerType");
				DllFn(GetPointerInfo, "User32.dll", "GetPointerInfo");
				DllFn(GetPointerPenInfo, "User32.dll", "GetPointerPenInfo");
				DllFn(GetPointerTouchInfo, "User32.dll", "GetPointerTouchInfo");
			};
			
			POINTER_INPUT_TYPE pointerType;
			

			UINT32 pointerId = GET_POINTERID_WPARAM(wParam);
			if(GetPointerType && GetPointerPenInfo && GetPointerType(pointerId, &pointerType)) {
				switch(pointerType){
					case PT_PEN:{
						POINTER_PEN_INFO ppi;
						if(GetPointerPenInfo(pointerId, &ppi)) {
							pen = true;
							if(ppi.penFlags & PEN_FLAG_BARREL)
								pen_barrel = true;
							if(ppi.penFlags & PEN_FLAG_INVERTED)
								pen_inverted = true;
							if(ppi.penFlags & PEN_FLAG_ERASER)
								pen_eraser = true;
							if(ppi.penMask & PEN_MASK_PRESSURE)
								pen_pressure = ppi.pressure / 1024.0;
							if(ppi.penMask & PEN_MASK_ROTATION)
								pen_rotation = ppi.rotation * M_2PI / 360;
							if(ppi.penMask & PEN_MASK_TILT_X)
								pen_tilt.x = ppi.tiltX * M_2PI / 360;
							if(ppi.penMask & PEN_MASK_TILT_Y)
								pen_tilt.y = ppi.tiltY * M_2PI / 360;
							
						}
						break;
					}
					case PT_TOUCH:{
						POINTER_TOUCH_INFO pti;
						if(GetPointerTouchInfo(pointerId, &pti)) {
							// Add something touch specific here some day maybe...
						}
						break;
					}
					default:{
						POINTER_INFO pi;
						if(GetPointerInfo(pointerId, &pi)) {
						}
						break;
					}
				}

				if(_this) switch(message){
					case WM_POINTERDOWN:
						ClickActivateWnd();
						DoMouse(LEFTDOWN, Point(p), 0);
						PostInput();
						break;
					case WM_POINTERUP:
						DoMouse(LEFTUP, Point(p), 0);
						PostInput();
						break;
					case WM_POINTERUPDATE:
						DoMouse(MOUSEMOVE, Point(p));
						DoCursorShape();
						break;
				}
				
			}
		}
		break;
	case WM_POINTERLEAVE:
		pen = false;
		break;
...

	case WM_LBUTTONDOWN:
		if(disableOldWMs) break;
...

	case WM_LBUTTONUP:
		if(disableOldWMs) break;
...

	case WM_MOUSEMOVE:
		if(disableOldWMs) break;



Without native POINTER sources, this one should use the original code all the way, I hope...

Best regards,

Tom
Re: Using Pen with U++ [message #56430 is a reply to message #56423] Thu, 11 March 2021 11:21 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
So I have some bad news, even if somewhat funny news:

With your code, it starts drawing those nasty initial lines with my XP-PEN... Sad Very Happy

[Updated on: Thu, 11 March 2021 11:22]

Report message to a moderator

Re: Using Pen with U++ [message #56431 is a reply to message #56430] Thu, 11 March 2021 11:53 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Laughing

OK, if I add this to the beginning of WindowProc():
	switch(message) {
		case WM_POINTERDOWN:
			RLOG("WM_POINTERDOWN");
			break;
		case WM_POINTERUPDATE:
			RLOG("WM_POINTERUPDATE");
			break;
		case WM_POINTERUP:
			RLOG("WM_POINTERUP");
			break;
		case WM_MOUSEMOVE:
			RLOG("WM_MOUSEMOVE");
			break;
		case WM_LBUTTONUP:
			RLOG("WM_LBUTTONUP");
			break;
		case WM_LBUTTONDOWN:
			RLOG("WM_LBUTTONDOWN");
			break;
	}


I will get this sequence for drawing one line:

...
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_POINTERDOWN
WM_POINTERUPDATE
WM_POINTERUPDATE
...
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_LBUTTONDOWN
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
...
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_POINTERUP
WM_MOUSEMOVE
WM_LBUTTONUP
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_MOUSEMOVE
...


How about you?

Best regards,

Tom
Re: Using Pen with U++ [message #56433 is a reply to message #56431] Thu, 11 March 2021 14:16 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Added some log to the testing code too.

	virtual void LeftDown(Point p, dword)
	{
		if(IsPointerPen()) {
			DLOG("Start line");
			drawing.Add().Add(MakeTuple(GetPenPressure(), p));
		}
		Refresh();
	}

	virtual void MouseMove(Point p, dword keyflags) {
		pos = p;
		if(IsPointerPen() && drawing.GetCount()) {
			DLOG("Drawing line, pressure: " << GetPenPressure());
			drawing.Top().Add(MakeTuple(GetPenPressure(), p));
		}
		Refresh();
	}


WM_MOUSEMOVE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_POINTERDOWN
WM_MOUSEMOVE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_LBUTTONDOWN
Start line
WM_MOUSEMOVE
Drawing line, pressure: 0.109375
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.12890625
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.1318359375
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.1337890625
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.1435546875
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.14453125
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.150390625
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.1689453125
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.1767578125
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.205078125
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.220703125
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.2421875
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.24609375
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.2578125
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.2607421875
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.2607421875
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.2607421875
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.2578125
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.2578125
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.2548828125
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.25390625
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.2548828125
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.2548828125
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.267578125
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.2666015625
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.2666015625
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.2685546875
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.267578125
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.267578125
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.267578125
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.26953125
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.2705078125
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.2705078125
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.271484375
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0.1015625
WM_POINTERUPDATE
WM_POINTERUP
WM_LBUTTONUP
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0
WM_POINTERUPDATE
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0
WM_POINTERUPDATE
WM_MOUSEMOVE
Drawing line, pressure: 0
WM_POINTERUPDATE
WM_MOUSEMOVE
WM_MOUSEMOVE
WM_MOUSEMOVE
WM_MOUSEMOVE
WM_MOUSEMOVE
WM_MOUSEMOVE
WM_MOUSEMOVE


Looking at it, maybe the problem is actually in testing code, at least partially? (drawing line continues after mouseup).

Also note that I am not getting any other WM_POINTER message than UPDATE....

P.S.: Why RLOG? Do you want to forget it in the code? Smile

[Updated on: Thu, 11 March 2021 14:17]

Report message to a moderator

Previous Topic: WString vs Grapheme Cluster idea (with possible flaw)
Next Topic: .gitignore
Goto Forum:
  


Current Time: Fri Mar 29 11:40:08 CET 2024

Total time taken to generate the page: 0.01964 seconds