Recent

Author Topic: Draw a line in the ScrollBox ?  (Read 1388 times)

majid.ebru

  • Hero Member
  • *****
  • Posts: 522
Draw a line in the ScrollBox ?
« on: April 21, 2024, 12:34:29 pm »
Hi
please help and guide me !

Is it possible to draw a line in the scrollbox with the onclick event and make it moveable?
Without using any components!! :)
« Last Edit: April 21, 2024, 01:03:33 pm by majid.ebru »

paule32

  • Sr. Member
  • ****
  • Posts: 285
Re: Draw line
« Reply #1 on: April 21, 2024, 12:50:14 pm »
The property: DragDrop, and events: OnDragOver, ... are your friends.

majid.ebru

  • Hero Member
  • *****
  • Posts: 522
Re: Draw line
« Reply #2 on: April 21, 2024, 01:04:22 pm »
The property: DragDrop, and events: OnDragOver, ... are your friends.

No my problem is draw a line in the ScrollBox no events of ScrollBox !

paule32

  • Sr. Member
  • ****
  • Posts: 285
Re: Draw a line in the ScrollBox ?
« Reply #3 on: April 21, 2024, 01:09:03 pm »
you can override the Paint methode

majid.ebru

  • Hero Member
  • *****
  • Posts: 522
Re: Draw a line in the ScrollBox ?
« Reply #4 on: April 22, 2024, 09:14:25 am »
how
can you explain ?

krolikbest

  • Sr. Member
  • ****
  • Posts: 251
Re: Draw a line in the ScrollBox ?
« Reply #5 on: April 22, 2024, 09:40:18 am »
Hi,
if you use scrollbox's Canvas then you have to write your own routines to detect if mouse is pressed near the line - let's say you set some delta(distance) and after pressing mouse Down/Up around cursor's point you check if there is some of your lines. To achive it you can simply use methods of the scrollbox like OnMouseDow, OnMouseUp, OnMouseMove. Something similar I did several months ago, see: https://www.youtube.com/watch?v=X2ojIqAhlfA

Regards

Handoko

  • Hero Member
  • *****
  • Posts: 5387
  • My goal: build my own game engine using Lazarus
Re: Draw a line in the ScrollBox ?
« Reply #6 on: April 23, 2024, 07:27:54 am »
Is it possible to draw a line in the scrollbox with the onclick event and make it moveable?

To achieve it, basically you need to solve these 3 things:

1. Draw the lines
This is the easiest. If you don't know how to do it, here has an example code showing how to draw lines on a scrollbox's canvas and the canvas of the object inside the scrollbox:
https://forum.lazarus.freepascal.org/index.php/topic,66899.msg513831.html#msg513831

2. Store the lines' information
Because you need to make them moveable, you need to store the basic information of the items. You can write your own data structure for information like: PosX, PosY, color, object_type, etc. And then you can use a dynamic array as the container for storing them. For more advanced usage you can use TList or FPObjectList. Here is a list of the available containers for Lazarus:
https://wiki.lazarus.freepascal.org/Data_Structures,_Containers,_Collections

3. Sprite picking
This is hardest part. Even you got a fully working code, you may still scratch your head for understanding it. If all the items have basic geometry shapes, rectangle for example you 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 different method. Mr.Madguy provided a fully working code for irregular shape sprite picking technique:
https://forum.lazarus.freepascal.org/index.php/topic,36871.msg246309.html#msg246309

Usually, I would provide a fully working demo but I'm sorry I am very busy recently. I cannot help.

 

TinyPortal © 2005-2018