Drawing arcs without using Circle 
Author Message
 Drawing arcs without using Circle

Is there any way of drawing an arc without using VB's built-in 'Circle'
command? I'm trying to draw lots of arcs at once and using 'Circle' seems to
slow the process down considerably.

I've got Mike Sutton's APIDraw module, but I can't find anything in there
that looks arc-like...

--
Ed Fielden, Cirencester, UK



Wed, 30 Mar 2005 07:36:57 GMT  
 Drawing arcs without using Circle

Quote:
> Is there any way of drawing an arc without using VB's built-in 'Circle'
> command? I'm trying to draw lots of arcs at once and using 'Circle' seems
to
> slow the process down considerably.

> I've got Mike Sutton's APIDraw module, but I can't find anything in there
> that looks arc-like...

You can use the Arc() API call.
Unfortunately I've not wrapped this in the current build of APIDraw but it
follows the same principles as the others, the Pen/Brush
selection/de-selection code is public in the module so you can still use the
library to deal with that whist using the API to do the drawing.  Arc() and
a few others (Including text) will most likely be in the next version when I
get some time to develop it further.
Hope this helps,

    Mike

 -- EDais --

 - Microsoft Visual Basic MVP -
WWW: Http://EDais.earlsoft.co.uk/




Wed, 30 Mar 2005 07:43:22 GMT  
 Drawing arcs without using Circle



Quote:
> > Is there any way of drawing an arc without using VB's built-in 'Circle'
> > command? I'm trying to draw lots of arcs at once and using 'Circle'
seems
> to
> > slow the process down considerably.

> > I've got Mike Sutton's APIDraw module, but I can't find anything in
there
> > that looks arc-like...

> You can use the Arc() API call.
> Unfortunately I've not wrapped this in the current build of APIDraw but it
> follows the same principles as the others, the Pen/Brush
> selection/de-selection code is public in the module so you can still use
the
> library to deal with that whist using the API to do the drawing.  Arc()
and
> a few others (Including text) will most likely be in the next version when
I
> get some time to develop it further.
> Hope this helps,

Thanks Mike. I'll have a go at APIArc-ing then!

--
Ed Fielden, Cirencester, UK



Wed, 30 Mar 2005 07:47:22 GMT  
 Drawing arcs without using Circle

Quote:
> Thanks Mike. I'll have a go at APIArc-ing then!

Here you go, I've just written an interim upgrade for you to include a
wrapping of the Arc and Pie API calls.  Add the following API declares
beneath the "PolyLine" declare:

'***
Public Declare Function Arc Lib "gdi32" (ByVal hdc As Long, ByVal X1 As
Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As
Long, ByVal Y3 As Long, ByVal X4 As Long, ByVal Y4 As Long) As Long
Public Declare Function Pie Lib "gdi32" (ByVal hdc As Long, ByVal X1 As
Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As
Long, ByVal Y3 As Long, ByVal X4 As Long, ByVal Y4 As Long) As Long
Public Declare Function SetArcDirection Lib "gdi32" (ByVal hdc As Long,
ByVal ArcDirection As Long) As Long
'***

Then these constants beneath the "TwoPi" definition:

'***
Private Const AD_COUNTERCLOCKWISE = 1
Private Const AD_CLOCKWISE = 2
'***

Then finally the meaty ones right at the end:

'***
Public Function DrawDCArc(TargDC As Long, inRectFrom As POINTAPI, inRectTo
As POINTAPI, inArcFrom As POINTAPI, _
    inArcTo As POINTAPI, Optional inClockwise As Boolean = False, Optional
pStyle As enuPS = psSolid, _
    Optional pWidth As Long = 1, Optional pCol As Long = vbBlack) As Long
    Dim hPen As Long, hOldPen As Long 'Draw an arc + custom pen

    hPen = PutNewPen(TargDC, pStyle, pWidth, pCol, hOldPen)
    DrawDCArc = DrawDCArcS(TargDC, inRectFrom, inRectTo, inArcFrom, inArcTo,
inClockwise) 'Draw the arc
    RestorePen TargDC, hPen, hOldPen
End Function

Public Function DrawDCArcS(TargDC As Long, inRectFrom As POINTAPI, inRectTo
As POINTAPI, _
    inArcFrom As POINTAPI, inArcTo As POINTAPI, Optional inClockwise As
Boolean = False) As Long
    Dim OldAD As Long

    OldAD = SetArcDirection(TargDC, IIf(inClockwise, AD_CLOCKWISE,
AD_COUNTERCLOCKWISE)) 'Set arc direction
    DrawDCArcS = Arc(TargDC, inRectFrom.x, inRectFrom.y, inRectTo.x,
inRectTo.y, inArcFrom.x, inArcFrom.y, inArcTo.x, inArcTo.y) 'Draw the arc
    SetArcDirection TargDC, OldAD
End Function

Public Function DrawDCPie(TargDC As Long, inRectFrom As POINTAPI, inRectTo
As POINTAPI, inArcFrom As POINTAPI, _
    inArcTo As POINTAPI, Optional inClockwise As Boolean = False, Optional
bCol As Long = vbWhite, _
    Optional bHatch As enuHS = hsSolid, Optional bStyle As enuBS = bsSolid,
Optional pStyle As enuPS = psSolid, _
    Optional pWidth As Long = 1, Optional pCol As Long = vbBlack) As Long
    Dim hBrush As Long, hOldBrush As Long 'Draw a pie segment + custom pen &
brush
    Dim hPen As Long, hOldPen As Long

    hBrush = PutNewBrush(TargDC, bCol, bHatch, bStyle, hOldBrush)
    hPen = PutNewPen(TargDC, pStyle, pWidth, pCol, hOldPen)
    DrawDCPie = DrawDCPieS(TargDC, inRectFrom, inRectTo, inArcFrom, inArcTo,
inClockwise) 'Draw the pie segment
    RestoreBrush TargDC, hBrush, hOldBrush
    RestorePen TargDC, hPen, hOldPen
End Function

Public Function DrawDCPieS(TargDC As Long, inRectFrom As POINTAPI, inRectTo
As POINTAPI, _
    inArcFrom As POINTAPI, inArcTo As POINTAPI, Optional inClockwise As
Boolean = False) As Long
    Dim OldAD As Long

    OldAD = SetArcDirection(TargDC, IIf(inClockwise, AD_CLOCKWISE,
AD_COUNTERCLOCKWISE)) 'Set arc direction
    DrawDCPieS = Pie(TargDC, inRectFrom.x, inRectFrom.y, inRectTo.x,
inRectTo.y, inArcFrom.x, inArcFrom.y, inArcTo.x, inArcTo.y) 'Draw the pie
segment
    SetArcDirection TargDC, OldAD
End Function
'***

Apologies for the atrocious word wrapping but trying to format that for a
newsreader would be ridiculous.  If you would prefer I can e-mail the new
code over instead if you don't want to pick through all that, let me know.
Here's an example of using them:

'***
Private Sub Form_Paint()
    DrawDCPie Form1.hdc, NewPointAPI(0, 0), NewPointAPI(200, 200), _
        NewPointAPI(100, 0), NewPointAPI(200, 100), False, vbRed, _
        sFDiagonal, bsHatched, psNull

    DrawDCArc Form1.hdc, NewPointAPI(0, 0), NewPointAPI(200, 200), _
        NewPointAPI(100, 0), NewPointAPI(200, 100), False, psSolid, 2,
vbBlue
End Sub
'***

It's a kind of odd API call this one hence it's odd wrapping, you have to
define a rectangle where the full circle would go, then two points that mark
the end points of the two ends of the arc/pie.  Since there's two way's of
interpreting drawing from one point on a closed shape to another point on
the same shape, there's also a flag which lets you choose if you want it
drawn clockwise or counter-clockwise.
Hope this helps,

    Mike

 -- EDais --

 - Microsoft Visual Basic MVP -
WWW: Http://EDais.earlsoft.co.uk/




Wed, 30 Mar 2005 08:17:28 GMT  
 Drawing arcs without using Circle


Quote:
> Here you go, I've just written an interim upgrade for you to include a
> wrapping of the Arc and Pie API calls.
<snip>
> It's a kind of odd API call this one hence it's odd wrapping, you have to
> define a rectangle where the full circle would go, then two points that
mark
> the end points of the two ends of the arc/pie.  Since there's two way's of
> interpreting drawing from one point on a closed shape to another point on
> the same shape, there's also a flag which lets you choose if you want it
> drawn clockwise or counter-clockwise.
> Hope this helps,

Indeed it does! That's fantastic Mike, thanks for that. I'd tried to put
some code in myself, but I did get some strange results. I just couldn't
work out what the 4 points were for. Now I know - I am eternally grateful...
:)

--
Ed Fielden, Cirencester, UK



Wed, 30 Mar 2005 18:44:44 GMT  
 Drawing arcs without using Circle
Quote:
> Indeed it does! That's fantastic Mike, thanks for that. I'd tried to put
> some code in myself, but I did get some strange results. I just couldn't
> work out what the 4 points were for. Now I know - I am eternally

grateful...

You're welcome, oh and the next version will also have documentation to
cover these little eventualities *g*

    Mike

 -- EDais --

 - Microsoft Visual Basic MVP -
WWW: Http://EDais.earlsoft.co.uk/




Wed, 30 Mar 2005 19:06:29 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. DRAWING ARCS AND CIRCLES IN VISUAL BASIC 4

2. Draw an arc with transparency

3. Drawing Arcs

4. Arc Drawing Question - Please help!

5. Help drawing arcs

6. Drawing and arc of an Ellipse

7. HELP!! - Drawing Arcs

8. HELP! Drawing arcs ***************

9. Drawing Arcs

10. Drawing Arcs

11. Drawing arcs during run-time: how?

12. Drawing ARC

 

 
Powered by phpBB® Forum Software