Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to draw line(s), arcs, rectangles, etc



Permlink Replies: 6 - Last Post: Oct 26, 2014 2:14 AM Last Post By: bernard roussely
Peter Philippa

Posts: 4
Registered: 11/5/99
How to draw line(s), arcs, rectangles, etc
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 24, 2014 4:53 PM
Hi,

Could someone post an example of how to draw a line, arc or rectangle in
Firemonkey XE6?

Thanks,
Peter
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: How to draw line(s), arcs, rectangles, etc
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 24, 2014 7:15 PM   in response to: Peter Philippa in response to: Peter Philippa
El 25/09/2014 1:53, Peter Philippa escribió:
Hi,

Could someone post an example of how to draw a line, arc or rectangle in
Firemonkey XE6?

Thanks,
Peter

By example, You can use de Canvas object in the form's OnPaint Event:

void __fastcall TForm1::FormPaint(TObject *Sender, TCanvas *Canvas, 
const TRectF &ARect)
{
    Canvas->BeginScene();
    Canvas->Stroke->Color = claRed;
    Canvas->StrokeThickness = 4;
    Canvas->DrawArc(TPointF(250, 180), TPointF(80, 60), 0.0f, 270.0f, 1.0f);
    Canvas->DrawRect(TRectF(100, 100, 200, 250), 10, 10, AllCorners, 1.0);
    Canvas->EndScene();
}
bernard roussely

Posts: 106
Registered: 2/8/05
Re: How to draw line(s), arcs, rectangles, etc
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 24, 2014 11:15 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Hello,

This works fine on Windows. Is there a reason why the drawings don't display on Android, like missing an init sequence for instance (other than the required TAlphaColor conversion)? I tried lots of coordinates starting from (0, 0) with no success.

Thanks,

bernard
Ross Tuck

Posts: 6
Registered: 6/2/12
Re: How to draw line(s), arcs, rectangles, etc
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 25, 2014 5:07 AM   in response to: bernard roussely in response to: bernard roussely
bernard roussely wrote:
Hello,

This works fine on Windows. Is there a reason why the drawings don't display on Android, like missing an init sequence for instance (other than the required TAlphaColor conversion)? I tried lots of coordinates starting from (0, 0) with no success.

Thanks,

bernard

Yes I've had the same issues, I use the following code to draw a single black line around the edge of my rect.

#ifdef __ANDROID__
 
	Canvas->Stroke->Color = TAlphaColor( 0xFF000000 );
	Canvas->DrawLine( TPointF( OldRect.Left+1  , OldRect.Top ) , TPointF( OldRect.Right , OldRect.Top ) , 1.0 );
	Canvas->DrawLine( TPointF( OldRect.Right , OldRect.Top ) , TPointF( OldRect.Right , OldRect.Bottom-1 ) , 1.0 );
	Canvas->DrawLine( TPointF( OldRect.Right , OldRect.Bottom-1 ) , TPointF( OldRect.Left+1  , OldRect.Bottom-1 ) , 1.0 );
	Canvas->DrawLine( TPointF( OldRect.Left+1  , OldRect.Bottom ) , TPointF( OldRect.Left+1  , OldRect.Top ) , 1.0 );
 
#elif _Windows
 
	MyPolygon[0] = TPointF( OldRect.Left  , OldRect.Top );
	MyPolygon[1] = TPointF( OldRect.Right , OldRect.Top );
	MyPolygon[2] = TPointF( OldRect.Right , OldRect.Bottom );
	MyPolygon[3] = TPointF( OldRect.Left  , OldRect.Bottom );
	MyPolygon[4] = TPointF( OldRect.Left  , OldRect.Top );
				
        Canvas->Stroke->Color = System::Uitypes::TAlphaColor( 0xFF000000 );
	Canvas->DrawPolygon( MyPolygon , 100 ); // 100
 
#endif


The DrawPolygon and DrawPath functions do not behave correctly in Android, and as you can see from the code above, that the coordinate system is different.

I can't wait to try OSX and iOS.
bernard roussely

Posts: 106
Registered: 2/8/05
Re: How to draw line(s), arcs, rectangles, etc.
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 25, 2014 5:44 AM   in response to: Ross Tuck in response to: Ross Tuck
Hi Ross,

Thanks for your time. I tried this:
	Canvas->BeginScene();
	Canvas->Stroke->Color = TAlphaColor(claRed); // I tried claBlack but switched to red because of the emulator's background
	Canvas->DrawLine( TPointF(  1, 20) , TPointF( 50, 20) , 1.0);
	Canvas->DrawLine( TPointF( 50, 20) , TPointF( 50, 99) , 1.0);
	Canvas->DrawLine( TPointF( 50, 99) , TPointF(  1, 99) , 1.0);
	Canvas->DrawLine( TPointF( 1, 100) , TPointF(  1, 20) , 1.0);
	Canvas->EndScene();


This displays just nothing on an S4 (except a label that I have as a 'marker') and terminates without doing anything on the emulator.

Any other hint as to what the problem is?

Regards,

bernard
Ross Tuck

Posts: 6
Registered: 6/2/12
Re: How to draw line(s), arcs, rectangles, etc.
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 25, 2014 5:53 PM   in response to: bernard roussely in response to: bernard roussely
bernard roussely wrote:
Hi Ross,

Thanks for your time. I tried this:
	Canvas->BeginScene();
	Canvas->Stroke->Color = TAlphaColor(claRed); // I tried claBlack but switched to red because of the emulator's background
	Canvas->DrawLine( TPointF(  1, 20) , TPointF( 50, 20) , 1.0);
	Canvas->DrawLine( TPointF( 50, 20) , TPointF( 50, 99) , 1.0);
	Canvas->DrawLine( TPointF( 50, 99) , TPointF(  1, 99) , 1.0);
	Canvas->DrawLine( TPointF( 1, 100) , TPointF(  1, 20) , 1.0);
	Canvas->EndScene();


This displays just nothing on an S4 (except a label that I have as a 'marker') and terminates without doing anything on the emulator.

Any other hint as to what the problem is?

Regards,

bernard

Unfortunately no.

What is the size of the canvas ?

But one thing I have found out is that this line

 	Canvas->DrawLine( TPointF( 50, 99) , TPointF(  1, 99) , 1.0);


draws a shorter line than this one

 	Canvas->DrawLine( TPointF(  1, 99) , TPointF( 50, 99)  , 1.0);


also if you draw a line up instead of down the screen.
bernard roussely

Posts: 106
Registered: 2/8/05
Re: How to draw line(s), arcs, rectangles, etc.
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 26, 2014 2:14 AM   in response to: Ross Tuck in response to: Ross Tuck
It looks like there is an issue if you try to draw directly on the form canvas. In my case nothing works on Android.

If I use the same drawings and the same coordinates inside a TImage that I dropped on the form, then everything I draw looks fine on the S4. This "drawing" app still doesn't run on the emulator (black screen then an error message).

So, in conclusion, the form canvas cannot be used the same way on Android and W7/8 or we are missing something.

Thanks for your help,

bernard
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02