Recent

Author Topic: Problem with Hints  (Read 1192 times)

simsee

  • Full Member
  • ***
  • Posts: 196
Problem with Hints
« on: December 03, 2024, 12:21:44 pm »
I try to simplify a simple problem that arises in a more complex context, about hints.

Suppose we have two controls visible on the screen. The rectangular perimeter around the larger one contains the smaller one. Let's also assume that the larger one is placed in the foreground (with BringToFront method), while the smaller one is placed in the background (with SendToBack method).

If the shape of the larger control is not rectangular, the other control is still visible. My problem is that in this case, when the mouse cursor goes over the smaller control, is displayed the hint of the larger one, not the hint of the smaller one, above which the cursor visually appears.

Is it possible to solve this problem?

Attached I show an example made with Shapes and two screenshots that show the problem.

Thanks.

Alexandr R

  • New Member
  • *
  • Posts: 26
Re: Problem with Hints
« Reply #1 on: December 03, 2024, 03:00:25 pm »
Hint срабатывает на прямоугольнную область в которой расположена фигура. Если прямоугольные области TShare не перекрываются всё работает отлично.  Наверное Вам надо сначала определить, что  указатель мыши находится внутри или на границе замкнутой фигуры (звезды или квадрата в Вашем примере) и только потом отобразить Hint (например используя THintWindiw).   

Hint is triggered by the rectangular area in which the figure is located. If the rectangular areas of TShare do not overlap, everything works fine. Probably you need to first determine that the mouse pointer is inside or on the border of a closed figure (a star or a square in your example) and only then display the Hint (for example, using THintWindiw).

Handoko

  • Hero Member
  • *****
  • Posts: 5382
  • My goal: build my own game engine using Lazarus
Re: Problem with Hints
« Reply #2 on: December 03, 2024, 04:43:03 pm »
Is it possible to solve this problem?

Sorry if it is off topic and maybe not what you want.

It seems you're developing some sort of graphics engine, if yes you really should study Mr.Madguy's sprite picking example code:
https://forum.lazarus.freepascal.org/index.php/topic,36871.msg246309.html#msg246309

That is about object detection for 2D graphics. If all the items have basic geometry shapes, rectangle for example you just need to loop the z-order and compare your mouse position with the shape's left-top most and right-bottom most coordinates. But if they have varies or irregular shapes, you need to use a different method. Mr.Madguy provided a fully working code for irregular shape sprite picking technique, it's maybe too advanced for beginners to understand, but with some patient studying to code, it's really worth your time.

After you understand how it works, you can easily write your own hint that works on any shapes.

lainz

  • Hero Member
  • *****
  • Posts: 4661
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Problem with Hints
« Reply #3 on: December 03, 2024, 07:51:56 pm »
In bgracontrols we use alpha channel to detect transparent areas.
Check bcimagebutton control.

simsee

  • Full Member
  • ***
  • Posts: 196
Re: Problem with Hints
« Reply #4 on: December 03, 2024, 08:02:25 pm »
Thanks for the replies.

I'm able to determine if the mouse is actually over a shape or not, with more or less complex mathematical formulas depending on the type of shape.

My problem is: once I have ascertained that the mouse is over a shape, how do I trigger the visualization of the hint? As far as I know the hint is always or never displayed in a control depending on the true or false value of its ShowHint property.

lainz

  • Hero Member
  • *****
  • Posts: 4661
  • Web, Desktop & Android developer
    • https://lainz.github.io/
Re: Problem with Hints
« Reply #5 on: December 03, 2024, 08:14:54 pm »
Can you add a custom drawn hint?

Or use THintWindow as suggested...

jamie

  • Hero Member
  • *****
  • Posts: 6791
Re: Problem with Hints
« Reply #6 on: December 03, 2024, 11:16:18 pm »
Have you looked at the Trunk or maybe the 4.0CR has it, the Tshape has extra features.

One of them is "ptInshape" and also you can assign your custom shape

As for the Hint issue, I think it's best to not use the HINTS in the shapes but the global one where you can examine the shape control and using the "PtInShape" feature to test the overlaid shapes.

Jamie
The only true wisdom is knowing you know nothing

Sieben

  • Sr. Member
  • ****
  • Posts: 372
Re: Problem with Hints
« Reply #7 on: December 03, 2024, 11:25:48 pm »
Where, I suppose,

the global one

refers to Application.OnShowHint which at design time can be accessed via TApplicationProperties.
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

simsee

  • Full Member
  • ***
  • Posts: 196
Re: Problem with Hints
« Reply #8 on: December 04, 2024, 12:08:54 am »
Thanks for your answers. I had thought about custom drawn hint, but due of my laziness I preferred to look for alternatives on the forum.

I didn't know THintWindow and it seems to me that it is the best solution for my case.

But I don't understand how to position the hints correctly. For example in ActivateHint method, to which origin are the coordinates referred? Thanks.
« Last Edit: December 04, 2024, 12:13:52 am by simsee »

Alexandr R

  • New Member
  • *
  • Posts: 26
Re: Problem with Hints
« Reply #9 on: December 04, 2024, 08:20:29 am »
see links on the topic:
'membership of a point to a closed figure"
https://habr.com/ru/articles/301102/;
https://www.geeksforgeeks.org/how-to-check-if-a-given-point-lies-inside-a-polygon/;
https://algolist.ru/maths/geom/belong/poly2d.php.

The THintWindow module can be used something like this.

Code: Pascal  [Select][+][-]
  1. unit msg_Hint;
  2.  
  3. {$mode ObjFPC}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, LazUtf8, Forms, Controls;
  9.  
  10. type
  11.  TMsgHint = Class(THintWindow)
  12.   public
  13.    constructor Create(aOwner: TComponent); override;
  14.    destructor  Destroy; override;
  15.    {Устанавливает над компонентом aControl Нint c c сообщением aMsg. Внимание:
  16.     компонент aControl должен иметь родителя.                                  }
  17.    procedure SetScope(aControl: TControl; aMsg: string);
  18.  end;
  19.  
  20. implementation
  21.  
  22. constructor TMsgHint.Create(aOwner: TComponent);
  23. begin
  24.  inherited Create(aOwner);
  25.  Self.HideInterval:= 4000; //время показа сообщения 4с.
  26.  Self.AutoHide:= True;
  27.  Self.Color     := $00B3FFFF; //слоновая кость
  28.  Self.Font.Color:= $000404FF; //красно-коричневый
  29.  Self.Alignment:= taRightJustify;
  30. end;
  31.  
  32. destructor  TMsgHint.Destroy;
  33. begin
  34.  inherited Destroy;
  35. end;
  36.  
  37. procedure TMsgHint.SetScope(aControl: TControl; aMsg: string);
  38. var
  39.  Rect : TRect;
  40.  pnt  : TPoint;
  41. begin
  42.  Rect:= Self.CalcHintRect(0, aMsg, nil);
  43.  if aControl.Width> Rect.Right then
  44.   Rect.Right:= aControl.Width;
  45.  pnt:= aControl.ClientOrigin;
  46.  Rect.Left:= pnt.X-2;             Rect.Top   := pnt.Y-Rect.Bottom;
  47.  Rect.Right:= pnt.X+Rect.Right-2; Rect.Bottom:= pnt.Y;
  48.  Self.ActivateHint(Rect, aMsg);
  49. end;
  50.  
  51. end.
  52.  
  53.  

Handoko

  • Hero Member
  • *****
  • Posts: 5382
  • My goal: build my own game engine using Lazarus
Re: Problem with Hints
« Reply #10 on: December 04, 2024, 04:37:21 pm »
... how do I trigger the visualization of the hint?

I haven't tried but I would write my own, a popup. For example:
https://forum.lazarus.freepascal.org/index.php/topic,48291.msg348084.html#msg348084

With some modification of the codes, like checking the OnMouseMove and probably with a TTimer delay before showing the popup. I believe that will be sufficient to achieve what you want.

 

TinyPortal © 2005-2018