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++
Re: Using Pen with U++ [message #56626 is a reply to message #56624] Mon, 29 March 2021 20:41 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Mirek,

I'm almost sure this problem is about CtrlCore not entirely knowing about pen down condition. In a way, this resembles the ::GetCursorPos() issue you just fixed, where ::GetCursorPos() was not entirely aware of pen position, but only knew it after default processing. In this case GetMouseLeft() asks Windows for the left button state, but pen down is not the same as left mouse button in this case and is not detected. E.g. mouseCtrl and captureCtrl may be affected by this fact.

Again, I'm not familiar enough with the CtrlCore to make it properly aware about pen down condition. Can you improve the 'pen down awareness' of CtrlCore?

I tried:
static bool pendown=false;
bool GetMouseLeft()   { return pendown || (!!(GetKeyStateSafe(VK_LBUTTON) & 0x8000)); }

and updating the flag with WM_POINTERDOWN/WM_POINTERDOWN, but this was not enough.

Best regards,

Tom
Re: Using Pen with U++ [message #56629 is a reply to message #56626] Mon, 29 March 2021 22:02 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi Mirek,

See the switching Ctrls/hwnds for WM_POINTER and WM_MOUSEMOVE messages while on top of menu:
[+     0 ms] WM_MOUSEMOVE  N3Upp7MenuBarE  : 0x6a82880 (hwnd 0xd3009a)
[+     0 ms] Ctrl::DoMouse() [141, 302]
[+     0 ms] MEvent0 [138, 19]
[+     0 ms] mouseCtrl != this
[+     0 ms] HasMouse() = false
[+     0 ms] HasFocus() = true
[+     0 ms] HasMouse() = true
[+     0 ms] HasFocus() = false
[+     0 ms] HasMouse() = false
[+     0 ms] HasFocus() = true
[+     0 ms] HasMouse() = true
[+     0 ms] MEvent0 [138, 19]
[+    15 ms] WM_POINTERUPDATE 5UWord  : 0x6b88070 (hwnd 0x7c02b4)
[+     0 ms] Ctrl::DoMouse() [141, 343]
[+     0 ms] MEvent0 [141, 197]
[+     0 ms] mouseCtrl != this
[+     0 ms] HasFocus() = false
[+     0 ms] HasMouse() = false
[+     0 ms] HasMouse() = true
[+     0 ms] HasMouse() = false
[+     0 ms] HasMouse() = true
[+     0 ms] WM_POINTERUPDATE 5UWord  : 0x6b88070 (hwnd 0x7c02b4)
[+     0 ms] Ctrl::DoMouse() [142, 343]
[+     0 ms] MEvent0 [142, 197]
[+     0 ms] MEvent0 [142, 197]
[+    16 ms] MEvent0 [142, 197]
[+     0 ms] WM_MOUSEMOVE  N3Upp7MenuBarE  : 0x6a82880 (hwnd 0xd3009a)
[+     0 ms] Ctrl::DoMouse() [142, 302]
[+     0 ms] MEvent0 [139, 19]
[+     0 ms] mouseCtrl != this
[+     0 ms] HasMouse() = false
[+     0 ms] HasFocus() = true

Although not shown here, the screen coordinates come in right for both events, but the translation differs in DoMouse() because the events end up in different Ctrls/hwnds. Therefore, also local coordinates mismatch. As you can see, WM_POINTERUPDATE lands in main window, whereas WM_MOUSEMOVE goes to drop down menu just as it should.

Hope this helps...

Best regards,

Tom

EDIT: Plain hovering on an open drop down menu makes both WM_POINTERUPDATE and WM_MOUSEMOVE land in the drop down menu:
[+     0 ms] WM_POINTERUPDATE N3Upp7MenuBarE  : 0x6a82880 (hwnd 0xb10064)
[+     0 ms] Ctrl::DoMouse() [124, 302]
[+     0 ms] MEvent0 [121, 19]
[+     0 ms] MEvent0 [121, 19]
[+     0 ms] MEvent0 [121, 19]
[+     0 ms] WM_MOUSEMOVE  N3Upp7MenuBarE  : 0x6a82880 (hwnd 0xb10064)
[+     0 ms] Ctrl::DoMouse() [124, 302]
[+     0 ms] MEvent0 [121, 19]
[+     0 ms] MEvent0 [121, 19]
[+    16 ms] MEvent0 [121, 19]
[+     0 ms] MEvent0 [121, 19]
[+     0 ms] WM_POINTERUPDATE N3Upp7MenuBarE  : 0x6a82880 (hwnd 0xb10064)
[+     0 ms] Ctrl::DoMouse() [124, 302]
[+     0 ms] MEvent0 [121, 19]
[+     0 ms] MEvent0 [121, 19]
[+     0 ms] WM_POINTERUPDATE N3Upp7MenuBarE  : 0x6a82880 (hwnd 0xb10064)
[+     0 ms] Ctrl::DoMouse() [123, 302]
[+     0 ms] MEvent0 [120, 19]
[+     0 ms] MEvent0 [120, 19]
[+     0 ms] MEvent0 [120, 19]
[+     0 ms] WM_MOUSEMOVE  N3Upp7MenuBarE  : 0x6a82880 (hwnd 0xb10064)
[+     0 ms] Ctrl::DoMouse() [123, 302]
[+     0 ms] MEvent0 [120, 19]
[+     0 ms] MEvent0 [120, 19]
[+    16 ms] MEvent0 [120, 19]
[+     0 ms] MEvent0 [120, 19]
[+     0 ms] WM_POINTERUPDATE N3Upp7MenuBarE  : 0x6a82880 (hwnd 0xb10064)
[+     0 ms] Ctrl::DoMouse() [123, 301]


Drag is the difference...

[Updated on: Mon, 29 March 2021 22:08]

Report message to a moderator

Re: Using Pen with U++ [message #56630 is a reply to message #56629] Tue, 30 March 2021 11:21 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Tom1 wrote on Mon, 29 March 2021 22:02
Hi Mirek,

See the switching Ctrls/hwnds for WM_POINTER and WM_MOUSEMOVE messages while on top of menu:


Looks like Wacom sends WM_POINTER to the window that has keyboard focus...

Can you add something like DDUMP(Name(GetFocusCtrl()) before WM_MOUSEMOVE / WM_POINT... ?

That said, the true reason is perhaps that Pen is altering mouseCtrl. That should be fixable...

Mirek

[+     0 ms] WM_MOUSEMOVE  N3Upp7MenuBarE  : 0x6a82880 (hwnd 0xd3009a)
[+     0 ms] Ctrl::DoMouse() [141, 302]
[+     0 ms] MEvent0 [138, 19]
[+     0 ms] mouseCtrl != this
[+     0 ms] HasMouse() = false
[+     0 ms] HasFocus() = true
[+     0 ms] HasMouse() = true
[+     0 ms] HasFocus() = false
[+     0 ms] HasMouse() = false
[+     0 ms] HasFocus() = true
[+     0 ms] HasMouse() = true
[+     0 ms] MEvent0 [138, 19]
[+    15 ms] WM_POINTERUPDATE 5UWord  : 0x6b88070 (hwnd 0x7c02b4)
[+     0 ms] Ctrl::DoMouse() [141, 343]
[+     0 ms] MEvent0 [141, 197]
[+     0 ms] mouseCtrl != this
[+     0 ms] HasFocus() = false
[+     0 ms] HasMouse() = false
[+     0 ms] HasMouse() = true
[+     0 ms] HasMouse() = false
[+     0 ms] HasMouse() = true
[+     0 ms] WM_POINTERUPDATE 5UWord  : 0x6b88070 (hwnd 0x7c02b4)
[+     0 ms] Ctrl::DoMouse() [142, 343]
[+     0 ms] MEvent0 [142, 197]
[+     0 ms] MEvent0 [142, 197]
[+    16 ms] MEvent0 [142, 197]
[+     0 ms] WM_MOUSEMOVE  N3Upp7MenuBarE  : 0x6a82880 (hwnd 0xd3009a)
[+     0 ms] Ctrl::DoMouse() [142, 302]
[+     0 ms] MEvent0 [139, 19]
[+     0 ms] mouseCtrl != this
[+     0 ms] HasMouse() = false
[+     0 ms] HasFocus() = true

Although not shown here, the screen coordinates come in right for both events, but the translation differs in DoMouse() because the events end up in different Ctrls/hwnds. Therefore, also local coordinates mismatch. As you can see, WM_POINTERUPDATE lands in main window, whereas WM_MOUSEMOVE goes to drop down menu just as it should.

Hope this helps...

Best regards,

Tom

EDIT: Plain hovering on an open drop down menu makes both WM_POINTERUPDATE and WM_MOUSEMOVE land in the drop down menu:
[+     0 ms] WM_POINTERUPDATE N3Upp7MenuBarE  : 0x6a82880 (hwnd 0xb10064)
[+     0 ms] Ctrl::DoMouse() [124, 302]
[+     0 ms] MEvent0 [121, 19]
[+     0 ms] MEvent0 [121, 19]
[+     0 ms] MEvent0 [121, 19]
[+     0 ms] WM_MOUSEMOVE  N3Upp7MenuBarE  : 0x6a82880 (hwnd 0xb10064)
[+     0 ms] Ctrl::DoMouse() [124, 302]
[+     0 ms] MEvent0 [121, 19]
[+     0 ms] MEvent0 [121, 19]
[+    16 ms] MEvent0 [121, 19]
[+     0 ms] MEvent0 [121, 19]
[+     0 ms] WM_POINTERUPDATE N3Upp7MenuBarE  : 0x6a82880 (hwnd 0xb10064)
[+     0 ms] Ctrl::DoMouse() [124, 302]
[+     0 ms] MEvent0 [121, 19]
[+     0 ms] MEvent0 [121, 19]
[+     0 ms] WM_POINTERUPDATE N3Upp7MenuBarE  : 0x6a82880 (hwnd 0xb10064)
[+     0 ms] Ctrl::DoMouse() [123, 302]
[+     0 ms] MEvent0 [120, 19]
[+     0 ms] MEvent0 [120, 19]
[+     0 ms] MEvent0 [120, 19]
[+     0 ms] WM_MOUSEMOVE  N3Upp7MenuBarE  : 0x6a82880 (hwnd 0xb10064)
[+     0 ms] Ctrl::DoMouse() [123, 302]
[+     0 ms] MEvent0 [120, 19]
[+     0 ms] MEvent0 [120, 19]
[+    16 ms] MEvent0 [120, 19]
[+     0 ms] MEvent0 [120, 19]
[+     0 ms] WM_POINTERUPDATE N3Upp7MenuBarE  : 0x6a82880 (hwnd 0xb10064)
[+     0 ms] Ctrl::DoMouse() [123, 301]


Drag is the difference...[/quote]
Re: Using Pen with U++ [message #56631 is a reply to message #56629] Tue, 30 March 2021 11:26 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Try CtrlCore/CtrlMouse.cpp:320:

if(e != PEN && mouseCtrl != this) {
Re: Using Pen with U++ [message #56632 is a reply to message #56631] Tue, 30 March 2021 11:36 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
mirek wrote on Tue, 30 March 2021 12:26
Try CtrlCore/CtrlMouse.cpp:320:

if(e != PEN && mouseCtrl != this) {

The focusCtrl is switching between the menubar and the menuitem regardless the above change. The logs are taken just before DoMouse call in WM_MOUSEMOVE and WM_POINTERUPDATE:
[+     0 ms] WM_MOUSEMOVE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+    16 ms] WM_POINTERUPDATE N3Upp8MenuItemE  : 0x6c60c60 (parent N3Upp7BarPaneE)
[+     0 ms] WM_POINTERUPDATE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+     0 ms] WM_POINTERUPDATE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+    15 ms] WM_POINTERUPDATE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+     0 ms] WM_POINTERUPDATE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+    16 ms] WM_POINTERUPDATE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+     0 ms] WM_POINTERUPDATE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+    15 ms] WM_POINTERUPDATE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+     0 ms] WM_POINTERUPDATE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+     0 ms] WM_MOUSEMOVE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+    16 ms] WM_POINTERUPDATE N3Upp8MenuItemE  : 0x6c60c60 (parent N3Upp7BarPaneE)
[+     0 ms] WM_POINTERUPDATE N3Upp8MenuItemE  : 0x6c60c60 (parent N3Upp7BarPaneE)
[+    16 ms] WM_POINTERUPDATE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+     0 ms] WM_POINTERUPDATE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+     0 ms] WM_MOUSEMOVE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+    15 ms] WM_POINTERUPDATE N3Upp8MenuItemE  : 0x6c60c60 (parent N3Upp7BarPaneE)
[+     0 ms] WM_POINTERUPDATE N3Upp8MenuItemE  : 0x6c60c60 (parent N3Upp7BarPaneE)
[+    16 ms] WM_POINTERUPDATE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+     0 ms] WM_POINTERUPDATE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+     0 ms] WM_MOUSEMOVE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+    16 ms] WM_POINTERUPDATE N3Upp8MenuItemE  : 0x6c60c60 (parent N3Upp7BarPaneE)
[+     0 ms] WM_POINTERUPDATE N3Upp8MenuItemE  : 0x6c60c60 (parent N3Upp7BarPaneE)
[+    15 ms] WM_POINTERUPDATE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+     0 ms] WM_POINTERUPDATE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+     0 ms] WM_MOUSEMOVE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+    16 ms] WM_POINTERUPDATE N3Upp8MenuItemE  : 0x6c60c60 (parent N3Upp7BarPaneE)
[+     0 ms] WM_POINTERUPDATE N3Upp8MenuItemE  : 0x6c60c60 (parent N3Upp7BarPaneE)
[+    15 ms] WM_POINTERUPDATE N3Upp8MenuItemE  : 0x6c60c60 (parent N3Upp7BarPaneE)
[+     0 ms] WM_POINTERUPDATE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+     0 ms] WM_MOUSEMOVE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+    16 ms] WM_POINTERUPDATE N3Upp8MenuItemE  : 0x6c60c60 (parent N3Upp7BarPaneE)
[+     0 ms] WM_POINTERUPDATE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+     0 ms] WM_POINTERUPDATE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+     0 ms] WM_MOUSEMOVE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+    16 ms] WM_POINTERUPDATE N3Upp8MenuItemE  : 0x6c60c60 (parent N3Upp7BarPaneE)
[+    15 ms] WM_POINTERUPDATE N3Upp8MenuItemE  : 0x6c60c60 (parent N3Upp7BarPaneE)
[+     0 ms] WM_POINTERUPDATE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)
[+     0 ms] WM_MOUSEMOVE N3Upp7BarPaneE  : 0x6bc2978 (parent N3Upp7MenuBarE)


Best regards,

Tom

EDIT: Fixed content.

[Updated on: Tue, 30 March 2021 11:41]

Report message to a moderator

Re: Using Pen with U++ [message #56633 is a reply to message #56632] Tue, 30 March 2021 12:00 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
OK, I tried to completely separate Pen from Mouse now. Please try the trunk.

Mirek
Re: Using Pen with U++ [message #56635 is a reply to message #56633] Tue, 30 March 2021 12:44 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi,

Thank you Mirek! Well done! Now the menus work beautifully.

Can you take a look at the attached RectTracker testcase? It includes my Sketcher class which inherits RectTracker. In order to draw short detailed curves with freehand (i.e. Alt+PenDrag), Pen() support is needed in RectTracker. The 2 cm drag threshold with Wacom prevents relying on mouse processing (i.e. // 2. option in comment).

Thanks and best regards,

Tom



  • Attachment: main.cpp
    (Size: 5.46KB, Downloaded 105 times)
Re: Using Pen with U++ [message #56637 is a reply to message #56635] Tue, 30 March 2021 15:26 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi Mirek,

The following changes would add Pen support to RectTracker (and the inherited Sketcher).

Add to RectTracker in CtrlCore.h:

public:
	virtual bool  Pen(Point p, const PenInfo &pn, dword keyflags);
	virtual void  DoMouseMove(Point p, dword);

protected:
	int				pointer;


Changes in LocalLoop.cpp:
RectTracker::RectTracker(Ctrl& master)
{
	pointer=Null; // << ADD THIS IN CONSTRUCTOR

...

bool  RectTracker::Pen(Point p, const PenInfo &pn, dword keyflags){ // ADD Pen() here
	if(IsNull(pointer)) pointer=1;
	if(pointer!=1) return false;

	switch(pn.action){
		case 0:
			DoMouseMove(p, keyflags);
			break;
		case PEN_DOWN:
			LeftDown(p, keyflags);
			break;
		case PEN_UP:
			LeftUp(p, keyflags);
			break;
	}
	return true;
}

void RectTracker::MouseMove(Point mp, dword){ // ADD NEW MouseMove here
	if(IsNull(pointer)) pointer=2;
	if(pointer!=2) return;
	DoMouseMove(mp,0);
}

void RectTracker::DoMouseMove(Point mp, dword) // RENAMED ORIGINAL MouseMove to DoMouseMove
{

... THIS IS THE ORIGINAL MouseMove() code here ...


Changes in Win32Proc.cpp:
static bool pendown=false; // ADD
bool GetMouseLeft()   { return pendown || !!(GetKeyStateSafe(VK_LBUTTON) & 0x8000); } // ADD 'pendown ||' here

...

				if(message == WM_POINTERUPDATE && GetPointerPenInfoHistory(pointerId, &hc, ppit)) {
					bool processed = false;
					for(int i = hc - 1; i >= 0; i--) {
						ProcessPenInfo(ppit[i]);
						POINT hp = ppit[i].pointerInfo.ptPixelLocation;
						CurrentMousePos =  hp; // << ADD UPDATING HERE
						ScreenToClient(hwnd, &hp);
						pen.history = (bool)i;
						processed = DoPen(hp);
					}

...

				switch(message) {
				case WM_POINTERDOWN:
					pendown=true; // << ADD set pendown here
					pen.action = PEN_DOWN;
					ClickActivateWnd();
					break;
				case WM_POINTERUP:
					pendown=false; // << ADD set pendown here
					pen.action = PEN_UP;
					break;
				}



The updated testcase including modified Sketcher is attached in main2.cpp.

Would this be acceptable, or do you have a more elegant solution?

Best regards,

Tom
  • Attachment: main2.cpp
    (Size: 5.27KB, Downloaded 102 times)
Re: Using Pen with U++ [message #56644 is a reply to message #56637] Tue, 30 March 2021 23:34 Go to previous messageGo to next message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
Upp build has been broken again. Most likely, this is not related to Pen stuff, but still ...
./umk reference SuggestCtrl CLANG -bus
/home/buildbot/worker/l-upp/build/reference/SuggestCtrl/main.cpp:54:21: error: address of overloaded function 'CharFilterToUpperAscii' is ambiguous
        ctrl.CompareFilter(CharFilterToUpperAscii);
                           ^~~~~~~~~~~~~~~~~~~~~~
/home/buildbot/worker/l-upp/build/reference/SuggestCtrl/main.cpp:5:12: note: candidate function
inline int CharFilterToUpperAscii(int c)
           ^
/home/buildbot/worker/l-upp/build/uppsrc/Core/String.h:954:5: note: candidate function
int CharFilterToUpperAscii(int c);
    ^
/home/buildbot/worker/l-upp/build/uppsrc/CtrlLib/SuggestCtrl.h:39:35: note: passing argument to parameter 'filter' here
        SuggestCtrl& CompareFilter(int (*filter)(int c))  { compare_filter = filter; return *this; }
                                         ^
1 error generated.


Regards,
Novo
Re: Using Pen with U++ [message #56647 is a reply to message #56637] Wed, 31 March 2021 10:37 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Mirek,

Something is preventing delivery of Pen() call to widgets inside a Splitter. Here's a testcase:
#include <CtrlLib/CtrlLib.h>

using namespace Upp;

struct Canvas: Ctrl {
	Point pos;
	
	Vector<Vector<Tuple<double, Pointf>>> drawing;

	PenInfo	pen;

	Canvas(){
		pos=Null;
		Zero(pen);
	}
	
	virtual bool Pen(Point p, const PenInfo& pn, dword keyflags) override {
		pen=pn;
		
		switch(pn.action){
			case PEN_DOWN:
				drawing.Add().Add(MakeTuple(pn.pressure, p));
				break;
			case 0: // Move
				if(!!pn.pressure && !drawing.IsEmpty()) drawing.Top().Add(MakeTuple(pn.pressure, p));
			case PEN_UP: // Finish
				Refresh();
				break;
		}
		return true;
	}

	virtual void Paint(Draw& w0) override {
		DrawPainter w(w0, GetSize());
		w.Co();
		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() << "Pressure: " << pen.pressure);
		Text(String() << "Rotation: " << pen.rotation);
		Text(String() << "Tilt: " << pen.tilt);
		Text(String() << "Barrel: " << pen.barrel);
		Text(String() << "Inverted: " << pen.inverted);
		Text(String() << "Eraser: " << pen.eraser);
	}
};

struct MyApp : TopWindow {
	Canvas c1;
	Canvas c2;
	Splitter s;
	
	MyApp(){
		Add(s.Horz(c1,c2));
	}
};

GUI_APP_MAIN { MyApp().Run(); }


Best regards,

Tom

EDIT: Fixed testcase crash when drawing across the splitter wall.

[Updated on: Wed, 31 March 2021 13:43]

Report message to a moderator

Re: Using Pen with U++ [message #56648 is a reply to message #56647] Wed, 31 March 2021 13:14 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Mirek,

How about this change in Ctrl::WindowProc() in Win32Proc.cpp?:
			auto DoPen = [&](Point p) {
				GuiLock __;
				eventCtrl = this;
				Ctrl *q = this;
				for(Ctrl *t = q; t; t=q->ChildFromPoint(p)) q = t;
				bool b = q->Pen(p, pen, GetMouseFlags());
				SyncCaret();
				return b;
			};

Now the for loop propagates the Pen to last child, and the Pen works in the above testcase.

Best regards,

Tom
Re: Using Pen with U++ [message #56649 is a reply to message #56648] Wed, 31 March 2021 13:46 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi,

Another issue: The mouse cursor in the above testcase does not get updated when using pen. If the cursor crosses the splitter wall, the wall -specific cursor will remain even when pen hovers on top of the drawing canvas. The cursor updating code must be absent in the DoPen function...

EDIT: How about this?
			auto DoPen = [&](Point p) {
				GuiLock __;
				eventCtrl = this;
				Ctrl *q = this;
				for(Ctrl *t = q; t; t=q->ChildFromPoint(p)) q = t;
				bool b = q->Pen(p, pen, GetMouseFlags());
				SyncCaret();
				Image m = CursorOverride();
				if(IsNull(m)) SetMouseCursor(q->CursorImage(p,GetMouseFlags()));
				else SetMouseCursor(m);
				return b;
			};


Best regards,

Tom

[Updated on: Wed, 31 March 2021 14:17]

Report message to a moderator

Re: Using Pen with U++ [message #56650 is a reply to message #56649] Wed, 31 March 2021 15:03 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
And one more issue shown with the testcase:

The Splitter wall cannot be moved with the pen. Again, the Splitter does not get capture until the pen has moved 2 cm, but unfortunately at that time the pen is no longer on top of the wall, but rather 2 cm away from it. If I drag back and cross the Splitter wall 2 or more centimeters away from the original starting point, it gets captured and the wall starts moving.

Best regards,

Tom
Re: Using Pen with U++ [message #56656 is a reply to message #56650] Thu, 01 April 2021 13:53 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Hi Mirek,

Just noticed that SetCapture()/ReleaseCapture() was not working with Pen. Here's a fix for that:
			auto DoPen = [&](Point p) {
				GuiLock __;
				eventCtrl = this;
				Ctrl *q = this;
				if(captureCtrl){
					q=captureCtrl;
					p+=GetScreenRect().TopLeft()-captureCtrl->GetScreenRect().TopLeft();
				}
				else for(Ctrl *t = q; t; t=q->ChildFromPoint(p)) q = t;
				
				bool b = q->Pen(p, pen, GetMouseFlags());
				SyncCaret();
				Image m = CursorOverride();
				if(IsNull(m)) SetMouseCursor(q->CursorImage(p,GetMouseFlags()));
				else SetMouseCursor(m);
				return b;
			};


Best regards,

Tom

EDIT: Fixed coordinate offset in captureCtrl...

[Updated on: Thu, 01 April 2021 15:41]

Report message to a moderator

Re: Using Pen with U++ [message #56657 is a reply to message #56656] Thu, 01 April 2021 16:22 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Mirek,

OK, it seems the following (along with the previous changes) fixes Splitter behavior with pen.

Splitter.h:
class Splitter : public Ctrl {
	int            pointer;
public:
	virtual void   Layout();
	virtual void   Paint(Draw& draw);
	virtual void   DoMouseMove(Point p, dword keyflags);
	virtual void   MouseMove(Point p, dword keyflags);
	virtual bool   Pen(Point p, const PenInfo &pn, dword keyflags);
	virtual void   LeftDown(Point p, dword keyflags);
	virtual void   LeftUp(Point p, dword keyflags);
...


Splitter.cpp:
...
void   Splitter::MouseMove(Point p, dword) {
	if(pointer==2) DoMouseMove(p,0);
}

void   Splitter::DoMouseMove(Point p, dword) {
	if(HasCapture() && mouseindex >= 0 && mouseindex < pos.GetCount()) {
		SetPos(ClientToPos(p), mouseindex);
		Refresh();
		WhenAction();
	}
}

bool   Splitter::Pen(Point p, const PenInfo &pn, dword keyflags){
	switch(pn.action){
		case 0:
			if(pointer==1 && !pn.history) DoMouseMove(p, keyflags);
			break;
		case PEN_DOWN:
			if(IsNull(pointer)) pointer=1;
			LeftDown(p, keyflags);
			break;
		case PEN_UP:
			LeftUp(p, keyflags);
			break;
	}
	return true;
}

void   Splitter::LeftDown(Point p, dword) {
	if(IsNull(pointer)) pointer=2;
	SetCapture();
	Refresh();
	mouseindex = FindIndex(p);
}

int Splitter::FindIndex(Point client) const {
	int best = -1;
	int maxdist = chstyle->width;
	for(int i = 0; i < pos.GetCount(); i++) {
		int dist = abs((vert ? client.y : client.x) - PosToClient(pos[i]));
		if(dist <= maxdist) {
			best = i;
			maxdist = abs(dist);
		}
	}
	return best;
}

void   Splitter::LeftUp(Point p, dword keyflags) {
	pointer=Null;
	if(HasCapture())
		WhenSplitFinish();
	ReleaseCapture();
	Refresh();
}
...
Splitter::Splitter() {
	pointer = Null; // << Initialize here
	chstyle = NULL;
...

Best regards,

Tom
Re: Using Pen with U++ [message #56659 is a reply to message #56657] Thu, 01 April 2021 17:29 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Tom1 wrote on Thu, 01 April 2021 16:22
Mirek,

OK, it seems the following (along with the previous changes) fixes Splitter behavior with pen.

Splitter.h:
class Splitter : public Ctrl {
	int            pointer;
public:
	virtual void   Layout();
	virtual void   Paint(Draw& draw);
	virtual void   DoMouseMove(Point p, dword keyflags);
	virtual void   MouseMove(Point p, dword keyflags);
	virtual bool   Pen(Point p, const PenInfo &pn, dword keyflags);
	virtual void   LeftDown(Point p, dword keyflags);
	virtual void   LeftUp(Point p, dword keyflags);
...


Splitter.cpp:
...
void   Splitter::MouseMove(Point p, dword) {
	if(pointer==2) DoMouseMove(p,0);
}

void   Splitter::DoMouseMove(Point p, dword) {
	if(HasCapture() && mouseindex >= 0 && mouseindex < pos.GetCount()) {
		SetPos(ClientToPos(p), mouseindex);
		Refresh();
		WhenAction();
	}
}

bool   Splitter::Pen(Point p, const PenInfo &pn, dword keyflags){
	switch(pn.action){
		case 0:
			if(pointer==1 && !pn.history) DoMouseMove(p, keyflags);
			break;
		case PEN_DOWN:
			if(IsNull(pointer)) pointer=1;
			LeftDown(p, keyflags);
			break;
		case PEN_UP:
			LeftUp(p, keyflags);
			break;
	}
	return true;
}

void   Splitter::LeftDown(Point p, dword) {
	if(IsNull(pointer)) pointer=2;
	SetCapture();
	Refresh();
	mouseindex = FindIndex(p);
}

int Splitter::FindIndex(Point client) const {
	int best = -1;
	int maxdist = chstyle->width;
	for(int i = 0; i < pos.GetCount(); i++) {
		int dist = abs((vert ? client.y : client.x) - PosToClient(pos[i]));
		if(dist <= maxdist) {
			best = i;
			maxdist = abs(dist);
		}
	}
	return best;
}

void   Splitter::LeftUp(Point p, dword keyflags) {
	pointer=Null;
	if(HasCapture())
		WhenSplitFinish();
	ReleaseCapture();
	Refresh();
}
...
Splitter::Splitter() {
	pointer = Null; // << Initialize here
	chstyle = NULL;
...

Best regards,

Tom


In other words, have we failed again? Smile (The very moment you start fixing code in CtrlLib, it is failure...)

Mirek
Re: Using Pen with U++ [message #56660 is a reply to message #56659] Thu, 01 April 2021 18:01 Go to previous messageGo to next message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
Well, I do not know... When using default (non-pen) processing, pen must be dragged 2 cm before WM_LBUTTONDOWN is first sent. Confused

I do not know if this is the reason why the Splitter wall does not get captured with SetCapture().

So, I'm not sure at all, if this is our/my failure or if it is Wacom or Microsoft issue... After all, a mouse drag effectively begins only few pixels away from the starting point while for wacom it takes 2 cm.

Best regards,

Tom

EDIT: More specifically: When I put the pen down on standard splitter and start dragging, the splitter first gets nothing. As pen proceeds on top of the adjacent Canvas, the Canvas receives Pen() move actions with pressure on. When pen has moved 2 cm, I would expect the splitter to finally react, but in fact it requires pen passing over the splitter wall at a range greater than 2 cm from the starting point in order for the capture to realize.

EDIT2: The reason for not getting the WM_LBUTTONDOWN is obviously the lack of default processing when all the WM_POINTER* are in fact processed in Canvas and end with return 0L; instead. However, if we let it do default processing, we will start getting some WM_MOUSEMOVEs too from pen even when WM_POINTERUPDATEs have actually been processed already.

Maybe this must be fixed on the application side then: If Pen() returns false for such moves when pen is not actively being used in the Canvas i.e. a pendown condition therein, then Splitter can work almost normally despite the 2 cm start-up threshold. Obviously, the MouseMove()s must be processed accordingly.

[Updated on: Thu, 01 April 2021 21:55]

Report message to a moderator

Re: Using Pen with U++ [message #56663 is a reply to message #56660] Thu, 01 April 2021 22:46 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
If all works with "pre-Pen-U++" (?), maybe we should try to get back to "pen is mouse" mode (no Pen method). Return 0L in pen handling.

The only problem then is how to implement "IsPen" method (we definitely need that one). I can do that with XP-PEN (quoted that a while back), but we need a realiable method that works for Wacom too.

Mirek
Re: Using Pen with U++ [message #56664 is a reply to message #56663] Thu, 01 April 2021 22:49 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Are you 100% sure this does not work with Wacom:

https://stackoverflow.com/questions/29857587/detect-if-wm-mo usemove-is-caused-by-touch-pen

?
Re: Using Pen with U++ [message #56666 is a reply to message #56664] Fri, 02 April 2021 08:26 Go to previous messageGo to previous message
Tom1
Messages: 1212
Registered: March 2007
Senior Contributor
mirek wrote on Thu, 01 April 2021 23:49
Are you 100% sure this does not work with Wacom:

https://stackoverflow.com/questions/29857587/detect-if-wm-mo usemove-is-caused-by-touch-pen

?


Last time I tried it did not work. It was zero all the time. Since then, I have reinstalled the Wacom drivers.

Now I get: "GetMessageExtraInfo() = 4283520772" for pen and "GetMessageExtraInfo() = 0" for mouse. These are present for e.g. WM_MOUSEMOVE and WM_LBUTTONDOWN.

So, I may have made some stupid mistake last time or the driver re-installation may have had an effect.

Best regards,

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


Current Time: Thu Mar 28 16:04:50 CET 2024

Total time taken to generate the page: 0.02535 seconds