Board index » cppbuilder » Drawing lines

Drawing lines


2004-06-21 08:21:23 PM
cppbuilder65
I have to draw interactively lines and shapes over a form . What's the most
indicate kind of component?
TPaintBox?
--
================================
Michele Santucci
Software Development Manager
Celin Avio S.r.l.
Via Fontevivo, 21/M 19100 La Spezia
tel. +39-0187564080
================================
 
 

Re:Drawing lines

"Michele Santucci" < XXXX@XXXXX.COM >wrote:
Quote
I have to draw interactively lines and shapes over a form . What's the most
indicate kind of component?
You need to be more specific. What exactly are you trying to
accomplish?
In the mean time, look at TShape and TChart.
~ JD
 

Re:Drawing lines

I've to write a simple application where the user can draw a poly line
interactively (i.e. drawing the first segment, then the second one ... whit
a simple point, click & draw mechanism ) every node of the line (the
junction between two different segments) then should then become
editable/moveable.
For what I can see the TShape object doesn't support user inputs since is a
nonwindowed control.
"JD" < XXXX@XXXXX.COM >ha scritto nel messaggio
Quote

"Michele Santucci" < XXXX@XXXXX.COM >wrote:
>I have to draw interactively lines and shapes over a form . What's the
most
>indicate kind of component?

You need to be more specific. What exactly are you trying to
accomplish?

In the mean time, look at TShape and TChart.

~ JD

 

{smallsort}

Re:Drawing lines

Quote
I've to write a simple application where the user can draw a poly
line
interactively (i.e. drawing the first segment, then the second one
... whit
a simple point, click & draw mechanism ) every node of the line (the
junction between two different segments) then should then become
editable/moveable.
I think you need to work directly with a TCanvas. I've just written
the following code to give you an idea on what to do. Please notice
this is really a bad-written code and surely it needs to be checked in
deep, but I hope it could be helpful.
It works on a form canvas direcly. Clicking on the form the polygon is
draw, instead if you hold Ctrl and drag a point, the point is moved
and the polygon entirely redraw. Remember, this really isn't the best
solution at all (but it took only 5 mins, as well). Suggestions are
welcome :-).
//--------------------------------------------------------------------
-------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include <vector>
//--------------------------------------------------------------------
-------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//--------------------------------------------------------------------
-------
std::vector<Windows::TPoint>Points;
int MovingPoint = -1;
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------
-------
void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton
Button,
TShiftState Shift, int X, int Y)
{
if (Shift.Contains(ssCtrl))
{
std::vector<Windows::TPoint>::iterator iter;
for (iter = Points.begin(); iter < Points.end(); iter++)
{
if ((abs(iter->x - X) < 3) && (abs(iter->y - Y) < 3))
{
MovingPoint = iter - Points.begin();
break;
}
}
}
else
{
MovingPoint = -1;
Points.push_back(Point(X, Y));
DrawAll();
}
}
//--------------------------------------------------------------------
-------
void __fastcall TForm1::DrawAll(void)
{
if (Points.size()>1)
{
Form1->Canvas->FillRect(Form1->ClientRect);
std::vector<Windows::TPoint>::iterator iter = Points.begin();
Form1->Canvas->MoveTo(iter->x, iter->y);
Form1->Canvas->Ellipse(iter->x - 2, iter->y - 2, iter->x + 2,
iter->y + 2);
iter++;
for (; iter < Points.end(); iter++)
{
Form1->Canvas->LineTo(iter->x, iter->y);
Form1->Canvas->Ellipse(iter->x - 2, iter->y - 2, iter->x +
2, iter->y + 2);
}
}
}
//--------------------------------------------------------------------
-------
void __fastcall TForm1::FormMouseMove(TObject *Sender, TShiftState
Shift,
int X, int Y)
{
if (Shift.Contains(ssCtrl))
{
if (MovingPoint != -1)
{
Points[MovingPoint].x = X;
Points[MovingPoint].y = Y;
DrawAll();
}
}
else
MovingPoint = -1;
}
//--------------------------------------------------------------------
-------
void __fastcall TForm1::FormMouseUp(TObject *Sender, TMouseButton
Button,
TShiftState Shift, int X, int Y)
{
MovingPoint = -1;
}
//--------------------------------------------------------------------
-------
HTH,
Steve.
 

Re:Drawing lines

Hello,
I am running Turbo Pascal 1.5 for Windows and constructing a program that
needs to be able to draw lines at various angles. To accomplish this I am
either going to try and import a bitmap that I created in an outside
program, such as Paint, and display it in pascal, or create a bitmap inside
of pascal and use the polyline function to draw lines, with the default pen.
Which one of these are easier? I have read the manual, and the help section
of Pascal and found the information there to be insufficent. Would it be
possible for someone to make a simple program that utilizes one of these
functions, so that I can analyze it? Please foward all answers to
burnedfaceless_at_gmail_dot_com.
Thank you,
Brian Abbott
 

Re:Drawing lines

"Kelly J. Burke" < XXXX@XXXXX.COM >wrote:
Quote
I am running Turbo Pascal 1.5 for Windows and constructing a program that
needs to be able to draw lines at various angles. To accomplish this I am
either going to try and import a bitmap that I created in an outside
program, such as Paint, and display it in pascal, or create a bitmap inside
of pascal and use the polyline function to draw lines, with the default pen.
Why not simply draw the line directly? What is the purpose of the
bitmap? You should be able to use basic trig calculations to determine
the starting and ending coordinates and simply draw directly to the
display.
Good luck.
Kurt
 

Re:Drawing lines

I am new to drawing and have the following problem;
Canvas->MoveTo(sx,sy); // memo2 left,top,height,width
ex=Memo3->Left+(Memo3->Width)/2;
ey=Memo3->Top+(Memo3->Height)/2;
Canvas->LineTo(ex,ey); //memo3
If the Memos are contained in a richedit the line does not show until I make the RE invisible. How else can I make the line appear on top?
 

Re:Drawing lines

"george" < XXXX@XXXXX.COM >wrote in message
Quote
Canvas->MoveTo(sx,sy); // memo2 left,top,height,width
ex=Memo3->Left+(Memo3->Width)/2;
ey=Memo3->Top+(Memo3->Height)/2;
Canvas->LineTo(ex,ey); //memo3
Where exactly are you calling that code from? Which Canvas are you trying
to draw to exactly?
Quote
If the Memos are contained in a richedit the line does not show until I
make the RE invisible.
It sounds like you are drawing on the form's Canvas, is that right? If so,
then of course it is going to appear behind the controls. That is what it
is supposed to do.
Quote
How else can I make the line appear on top?
You have to draw on the individual controls themselves, such as with a
TControlCanvas object. Or else draw onto the Screen directly (which will be
on top of everything).
Gambit
 

Re:Drawing lines

OK, that looks good; I will experiment with what you have written.
Thanks a lot,
George
"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote

"george" < XXXX@XXXXX.COM >wrote in message
news:46f7e72c$ XXXX@XXXXX.COM ...

>Canvas->MoveTo(sx,sy); // memo2 left,top,height,width
>ex=Memo3->Left+(Memo3->Width)/2;
>ey=Memo3->Top+(Memo3->Height)/2;
>Canvas->LineTo(ex,ey); //memo3

Where exactly are you calling that code from? Which Canvas are you trying
to draw to exactly?
 

Re:Drawing lines

How do I specify which Canvas I want to use? I am new to canvases and none of the examples seem to set the canvas; they just go straight in. How can I do either of the suggestions? Use the control's canvas or the screen's?
George.
"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote

"george" < XXXX@XXXXX.COM >wrote in message
news:46f7e72c$ XXXX@XXXXX.COM ...
>
You have to draw on the individual controls themselves, such as with a
TControlCanvas object.
Or else draw onto the Screen directly (

Gambit


 

Re:Drawing lines

"george" < XXXX@XXXXX.COM >wrote in message
Quote
How do I specify which Canvas I want to use?
It depends on which object you are accessing it from. Each control and form
has its own Canvas.
Quote
How can I do either of the suggestions?
Use the control's canvas
Did you look at the TControlCanvas class yet, like I suggested?
Quote
or the screen's?
There is nothing in the VCL for that. You have to use the Win32 API
directly, specifically the GetDC() function. Pass it a NULL window handle
to get the HDC for the screen. If you wan, you can instantiate an instance
of TCanvas and assign the HDC to the Canvas's Handle property.
Gambit
 

Re:Drawing lines

Yes I looked at TControlCanvas but it doesn't tell me how to link to the control.
"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote

"george" < XXXX@XXXXX.COM >wrote in message
news:46f91532$ XXXX@XXXXX.COM ...

>How do I specify which Canvas I want to use?


Did you look at the TControlCanvas class yet, like I suggested?

 

Re:Drawing lines

"george" < XXXX@XXXXX.COM >wrote in message
Quote
Yes I looked at TControlCanvas but it doesn't
tell me how to link to the control.
Yes, it does. Did you read the documentation carefully? TControlCanvas
has a Control property for that.
Gambit
 

Re:Drawing lines

Thank you, Remy, for all that. I can now draw lines where I want. I was looking for a Canvas property under TControl.
George.
"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote

"george" < XXXX@XXXXX.COM >wrote in message
news:46f95934$ XXXX@XXXXX.COM ...

>Yes I looked at TControlCanvas but it doesn't
>tell me how to link to the control.

Yes, it does. Did you read the documentation carefully? TControlCanvas
has a Control property for that.


Gambit