Recent

Author Topic: How to show Selected component ICON as a mouse pointer over forms?  (Read 8540 times)

jamie

  • Hero Member
  • *****
  • Posts: 6090
 Is there anyway to have the mouse pointer tail a ICON image of the selected component on the component
tool bar ?
 
 I have this issue that sometimes I forget to cancel the selection from the toolbar and when I click an
existing component on the form it then drops that selected component there instead on top of the button
for example that I want the OI to come in focus on..

 It would be nice to have the cursor image change to the icon image of the currently selected component on the
tool bar as a reminder of what is going to happen when I click somewhere on the form!

 This of course should only appear as you hover over the forms, etc.

 I looked and can't see anything, maybe I missed it...?

The only true wisdom is knowing you know nothing

sash

  • Sr. Member
  • ****
  • Posts: 366
Re: How to show Selected component ICON as a mouse pointer over forms?
« Reply #1 on: November 21, 2018, 10:07:22 am »
Is this question about IDE?
Lazarus 2.0.10 FPC 3.2.0 x86_64-linux-gtk2 @ Ubuntu 20.04 XFCE

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: How to show Selected component ICON as a mouse pointer over forms?
« Reply #2 on: November 21, 2018, 11:49:57 pm »
Yes, I would of thought that to be obvious?

 I  know how to do such things in my own code  :)
The only true wisdom is knowing you know nothing

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: How to show Selected component ICON as a mouse pointer over forms?
« Reply #3 on: November 22, 2018, 01:09:16 am »
A patch would be accepted if you decide to implement it.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: How to show Selected component ICON as a mouse pointer over forms?
« Reply #4 on: November 22, 2018, 04:00:11 am »
We'll see, maybe I will  :D
 
The only true wisdom is knowing you know nothing

sash

  • Sr. Member
  • ****
  • Posts: 366
Re: How to show Selected component ICON as a mouse pointer over forms?
« Reply #5 on: November 22, 2018, 11:31:52 am »
Yes, I would of thought that to be obvious?

It would be much closer to obvious when posted in dedicated section "Using the Lazarus IDE".
Lazarus 2.0.10 FPC 3.2.0 x86_64-linux-gtk2 @ Ubuntu 20.04 XFCE

balazsszekely

  • Guest
Re: How to show Selected component ICON as a mouse pointer over forms?
« Reply #6 on: November 22, 2018, 01:26:21 pm »
I did implement this feature, but there is a small problem. To illustrate the issue I attach a small project. Just press the button 2-3 times and the bug is already visible(tested only on windows). After the issue is fixed I will attach the patch.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: How to show Selected component ICON as a mouse pointer over forms?
« Reply #7 on: November 22, 2018, 08:23:48 pm »
I did implement this feature, but there is a small problem. To illustrate the issue I attach a small project. Just press the button 2-3 times and the bug is already visible(tested only on windows). After the issue is fixed I will attach the patch.
I tested with GTK2 and QT on Linux and it works well. Clicking the button many times causes no problems. What is the bug on Windows?
I also added:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormClick(Sender: TObject);
  2. begin
  3.   Screen.Cursor := crDefault;
  4. end;
to get the normal cursor back when the form's background is clicked. It works, too.

BTW, I did not know how to switch to a custom cursor like that. Cool!
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

balazsszekely

  • Guest
Re: How to show Selected component ICON as a mouse pointer over forms?
« Reply #8 on: November 22, 2018, 10:30:05 pm »
I tested with GTK2 and QT on Linux and it works well. Clicking the button many times causes no problems. What is the bug on Windows?

The first two clicks are OK, then the following sigsegv appears(screenshot1) and the assembler window pops up(screenshot2). The issue is always reproducible. GTK2 and QT is indeed "immune" to this bug, win32/win64 and carbon on the other hand are not. I did not test with cocoa.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: How to show Selected component ICON as a mouse pointer over forms?
« Reply #9 on: November 24, 2018, 12:17:50 pm »
The first two clicks are OK, then the following sigsegv appears(screenshot1) and the assembler window pops up(screenshot2). The issue is always reproducible.
I tested with my Windows under VirtualBox. I updated Lazarus trunk sources and made a similar application. No sigsegv nor other problems.
Can others reproduce the problem?
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: How to show Selected component ICON as a mouse pointer over forms?
« Reply #10 on: November 24, 2018, 12:36:19 pm »
Running GetMem's demo from reply #6 on Win 10 (64bit) I see exactly the same issue that he is reporting (crash at third click at button) when I compile a 32 bit application (Laz trunk, just updated / fpc 3.0.4). A 64bit application, on the other hand, does not show the issue.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: How to show Selected component ICON as a mouse pointer over forms?
« Reply #11 on: November 24, 2018, 03:08:16 pm »
A 64bit application, on the other hand, does not show the issue.
Ok, mine is 64bit. Very strange, what can cause it?
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: How to show Selected component ICON as a mouse pointer over forms?
« Reply #12 on: November 25, 2018, 12:48:20 am »
There appears to be something wrong with the CursorImage.Assign, if you skip that it does not fault, however is
also does not assign an image....

I dug into my old code and found something using partially the example here posted...
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button2Click(Sender: TObject);
  2. Var
  3.   C,M:Tbitmap;
  4.   I:TIconInfo;
  5. begin
  6.   C := TBitmap.Create;
  7.   M := TBitmap.Create;
  8.   iml.GetBitmap(0, C);
  9.   iml.GetBitmap(1,M);
  10.   I.fIcon := false;
  11.   I.Xhotspot :=0;
  12.   I.Yhotspot :=0;
  13.   I.hbmColor := C.Handle;
  14.   I.hbmMask  := M.Handle;
  15.   DestroyCursor(Screen.Cursors[crComponent]);
  16.   Screen.Cursors[crComponent] := CreateIconIndirect(I);
  17.   C.Free;
  18.   M.Free;
  19.   Screen.Cursor := crComponent;
  20. end;                            
  21.  

If you take the example posted here and add another button and drop this code in it, you'll see it works with out
issues in the 32bit windows target, I assume it should also work elsewhere too.

P.S.
  I didn't bother to set the mask, I just used the second image for it but it seems to produce what you see..
.
« Last Edit: November 25, 2018, 01:15:19 am by jamie »
The only true wisdom is knowing you know nothing

balazsszekely

  • Guest
Re: How to show Selected component ICON as a mouse pointer over forms?
« Reply #13 on: November 26, 2018, 06:18:48 am »
@jamie
CreateIconIndirect is a windows specific function: https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-createiconindirect , you cannot use it in a cross platform IDE.

balazsszekely

  • Guest
Re: How to show Selected component ICON as a mouse pointer over forms?
« Reply #14 on: November 26, 2018, 07:47:40 am »
TCursorImage is very buggy, even when 64 bit is used, the Debug IDE will report an invalid memory location(gtk2 included). In order to prevent it I have to comment out the following line:
Code: Pascal  [Select][+][-]
  1. CursorImage.Free
which of course will lead to memory leak. Anyway I attach the patch, the idea is very simplistic in my opinion. Just create a new form/frame, select a component then move the mouse over the designer area. The cursor will take the image of the component. If no component is selected nothing happens. I think this was @jamie's request in his first post.

PS: Let's hope somebody will fix TCursorImage, otherwise the patch is useless.
PS1: Removed patch, going with @jamie's solution(see more recent posts)
« Last Edit: November 26, 2018, 11:24:27 am by GetMem »

 

TinyPortal © 2005-2018