Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-03

Looking for a suitable graphics library/component

6 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Adrian Maier

Hello,

I am seeking for some advice regarding what graphics library to use for a new project.

I am aware that the application can be done by drawing lines, points and text within a canvas. But I am hoping to find out about the existence of some already existing libraries that would ease the development ...

The application will be a railway route viewer (it's a tool that will be useful for me at work). I'll try to explain next what does it involve.
- the description of a train station tracknet is read from an xml file (the tracknet is like a spider web)
- a route is a concrete path of a train ; it's a set of connected track segments
- within the application i intend to represent the route as a long horizontal line
- on the route i need to represent elements (signals, points, balises). At a given location there can be more than one element.
- i need zooming and horizontal scrolling
- i need to be able to click on an element (and display information about it)
- there are many kinds of "areas" that also need to be marked visually (for example the max speed areas)
- in future I might also want to add a moving train
- i'll need a configurable annotation system (enable/disable areas, enable/disable labels)
- did i already mention zooming and scrolling ? ;)

My feeling is that it would be tedious to develop such a GUI application using only lines, points and rectangles.

So, does anyone happen to have suggestion regarding what would be the most suitable widget set or library for building such an application ?

Thanks,
Adrian

Reply by email

Anthony Walter
to Adrian Maier

For drawing lines, shapes, fills, on Linux I'd recommend using cairo. On Windows I'd say you should use GDI or GDI+. You can find pascal files importing the functions for those libraries using google. Some of them may come with FPC.

For widgets, if you are using Lazarus, it comes with a widget toolkit. Then there is also the free pascal gui tookit located here: http://fpgui.sourceforge.net/

Finally, for handling scrolling, what you need to do is determine the max bounds of your area, compare that to screen area and your drawing scale (your zoom factor). Use that to recalculate both the horizontal and vertical scroll bar information (page size, scroll size) when the draw area is resized and update the scroll bars accordingly.

When you receive a scroll position change notification (the user drags the scroll bar) you call some api to scroll the drawing (such as ScrollWindowEx), which will invalidate a dirty rectangle in your window.

When you receive a paint notification (either when the user scrolls or a window is dragged over your window), you should also retrieve the dirty rectangle. Then you need to find the rectangles of your drawn objects that intersect the dirty rectangle. Redraw objects that intersect the dirty rectangle.

If the user zooms in or out, invalidate the entire area.

It's all pretty standard stuff ...
http://imagebot.org/snapshops/phun-gears-builder.jpg

Reply by email

Horacio Jamilis
to Adrian Maier: I am seeking for some advice regarding what graphics library to use for a new project. I…

You could take a look to AggPas.

Good luck!

Horacio

Adrian Maier wrote 42 lines
Hello, I am seeking for some advice regarding what graphics library to use for a new project. I am aware that the application can be done by drawing lines, points and text within a canvas. But I am hoping to find out about the existence of some already existing libraries that would ease the development ... The application will be a railway route viewer (it's a tool that will be useful for me at work). I'll try to explain next what does it involve. - the description of a train station tracknet is read from an xml file (the tracknet is like a spider web) - a route is a concrete path of a train ; it's a set of connected track segments - within the application i intend to represent the route as a long horizontal line - on the route i need to represent elements (signals, points, balises). At a given location there can be more than one element. - i need zooming and horizontal scrolling - i need to be able to click on an element (and display information about it) - there are many kinds of "areas" that also need to be marked visually (for example the max speed areas) - in future I might also want to add a moving train - i'll need a configurable annotation system (enable/disable areas, enable/disable labels) - did i already mention zooming and scrolling ? ;) My feeling is that it would be tedious to develop such a GUI application using only lines, points and rectangles. So, does anyone happen to have suggestion regarding what would be the most suitable widget set or library for building such an application ? Thanks, Adrian _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply by email

Adrian Maier
to Anthony Walter: For drawing lines, shapes, fills, on Linux I'd recommend using cairo. On Windows I'd say…
Anthony Walter wrote 29 lines
For drawing lines, shapes, fills, on Linux I'd recommend using cairo. On Windows I'd say you should use GDI or GDI+. You can find pascal files importing the functions for those libraries using google. Some of them may come with FPC. For widgets, if you are using Lazarus, it comes with a widget toolkit. Then there is also the free pascal gui tookit located here: http://fpgui.sourceforge.net/ Finally, for handling scrolling, what you need to do is determine the max bounds of your area, compare that to screen area and your drawing scale (your zoom factor). Use that to recalculate both the horizontal  and vertical scroll bar information (page size, scroll size) when the draw area is resized and update the scroll bars accordingly. When you receive a scroll position change notification (the user drags the scroll bar) you call some api to scroll the drawing (such as ScrollWindowEx), which will invalidate a dirty rectangle in your window. When you receive a paint notification (either when the user scrolls or a window is dragged over your window), you should also retrieve the dirty rectangle. Then you need to find the rectangles of your drawn objects that intersect the dirty rectangle. Redraw objects that intersect the dirty rectangle. If the user zooms in or out, invalidate the entire area. It's all pretty standard stuff ... http://imagebot.org/snapshops/phun-gears-builder.jpg

Thanks Anthony for your answers.

I will keep in mind these suggestions if I fail to find a higher-level component.
(for example, the TAChart is a "higher-level" component for drawing charts that is much more convenient to use compared to drawing the chart from scratch).

Ideally, I am hoping that already exists some kind of "svg canvas" that can be used in fpgui or Lazarus applications. For example: if I draw a rectangle in the
canvas I want to be able to later :
- change color
- modify size/position
- associate it with a "mouse click" event

I didn't mention that I will need to handle in parallel multiple coordinates systems:
- number of meters
- position withing each track segment (each segment has a starting km and an ending km). And it's possible that a segment ends at km=35.4 and the next one
begins at km=38.2 . It is even possible that the next segment has coordinates in
reverse order.
- position relative to balises
So the problem itself is relatively mind-twisting .

It would be really nice to find a component that allows me to add and manipulate
the graphical objects in a "scalar-graphics" way , that takes care of drawing on-screen without forcing me to go into the details .

Adrian

Reply by email

Anthony Walter
to Adrian Maier: Thanks Anthony for your answers. I will keep in mind these suggestions if I fail to find…

Oh, you want a retained mode graphics system. That should be pretty easy to write yourself.

Just write a class like TDrawable with a Paint(), HitTest(Point), and Intersects(Rect) methods and derive from that to have your different drawn types.

Keep a list of those items in your drawing surface.

Call HitTest(MousePoint) when the mouse moves over the drawing area and track the hot/pressed/captured item.

When you surface needs to be painted, loop through the list and if DrawableItem.Intersects(DirectRect) then DrawableItem.Paint().

I don't think you'll find a ready made system to accommodate all your drawing needs.

Reply by email