开发者

VCL - drawing a room

I am still trying to draw a floorplan (in BCB 6).

I already asked a few questions. As a result of Seeking floorplan design VCL toolbar I bought the TMC components.

Looking for non-rectangular panel VCL component got me close, but not quite there.

So, let's try again...


Some sort of panel, I guess. With nice thick border lines (walls) are around the edges, maybe 5 or even 10 pixels, so default panels won't do it.

I can't just draw lines separately, as they need to resize with the form. So, either I ties lines to panels (owner property) and redraw them ... (when? Form resize?, Panel resize?)

Or I can make my own panel component.

In either case, I need to be able to interrupt the lines with openings for doors - or do I add a door component? But then I need to tie that to the panel, in case of form resize.

How best to implement? It doesn't have to be too fancy, but something like this...

=============================================
|              ||       ||                  |
|              ||       ||                  |
|              ||       ||                  |
|              ||       ||                  |
===   =============   =============    ======
|              ||                           |
|                                           |
|              ||                           |
=============================================

See? multiple doors too; preferably non-rectangular rooms (at least L-shape) and resizable with the form开发者_运维百科.

Any ideas?


I don't know if this is a solution that will fit your scenario, but if I were to design a similar application, I think I would take advantage of the easy nature of extending with new components in the VCL framework. I'd build components for the various graphical elements, door, wall, etc. I'd make a common object that they could inherit from.

For instance I'd make a TFloorplanElement component that all my graphical components could inherit from, I'd make the TFloorplanElement inherit from TGraphicControl to take advantage of the Anchor property given by TControl, and the Canvas provided by TGraphicControl. I wouldn't use a custom TPanel for this, I don't think the overhead of the windows handle provided by TWinControl is needed here.

For walls I'd make a component inheriting from my TFloorplanElement that is given two endpoints to connect the wall to, this could be either a door on one side and another wall on the other side, or any other combination of TFloorplanElement descendants. You need to have some sort of event handling for when either of these corners are moved, what you need to do in this case simply readjust the coordinates of your wall to the coordinates of the corner element.

One way you could solve the problem with form resizing, is by using a container control for your TFloorplanElement components, I guess that is what the Diagramming Studio is doing, but if you create a container component (TFloorplanContainer for instance) you could specify position of elements within in percentage, or have a scaling factor that was adjusted when the container was resized. The container ofcourse would be using its anchor properties binding it to the borders of its own container (ie. the form).

And whenever the container was resized you would redraw the containing elements. As I said to begin with, I'm not sure whether this is a solution that will work for you, or with the diagramming studio you use, but it is one approach I would consider, if I were in your place.


Take a look at TSimpleGraph, which might get you a huge head start on this. It's at: http://www.delphiarea.com/products/delphi-components/simplegraph/

It's a FREE component that provides a panel, with a huge assortment of methods, properties and places for event handlers, and the effect is pretty gorgeous. They provide a nice exe demo that shows of some of the possibilities. They have defined objects for various shapes and lines, but with some work I think you could add your own stock things like walls, etc.

If it works for you, TSimpleGraph would provide a nice housing, while letting you concentrate on the meat of your app.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜