Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Code Samples & Tips
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Code Samples & Tips Share your recent discoveries and ideas with other users.


Different Line Types


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-18-2008, 04:17 PM
Knows the basics
 
Join Date: May 2008
Posts: 86
Default Different Line Types

Hi

I wonder if anybody can help me? While I am busy with a Topographical survey, the points get plotted on the screen as they come from the Total Station or GPS. I can then add lines, text, circles, etc to the surveyed points, which means that the drawing will be nearly finished when I go back to the office.

My question is, is there any way that I can have different line types, i.e. solid, dashed, dot dashed, etc.

Thanks
Michael
Reply With Quote
  #2 (permalink)  
Old 05-18-2008, 05:45 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,185
Default

You will need to write the drawing algorithms yourself.
The following code demonstrates a simple way to draw dashed lines:
(length is the length of each section in the dashed line)
Code:
Sub Globals
    'Declare the global variables here.
    Dim xx,yy
End Sub

Sub App_Start
    Form1.Show
End Sub

Sub DashLine(length,x1,y1,x2,y2,color)
    b = ATan((y2-y1)/(x2 + 0.00001 - x1))
    total = Sqrt((x2-x1)^2+(y2-y1)^2)
    x = x1
    y = y1
    cs = Cos(b) * length
    sn = Sin(b) * length
    If x2 < x1 Then 
        cs = -cs
        sn = -sn
    End If
    For i = 0 To total Step 2*length
        xEnd = x + cs
        yEnd = y + sn
        form1.Line(x,y,xend,yend,color)
        x = xEnd + cs
        y = yEnd + sn
    Next
End Sub


Sub Form1_MouseDown (x,y)
    DashLine(5,xx,yy,x,y,cBlue)
    xx = x
    yy = y
End Sub
Reply With Quote
  #3 (permalink)  
Old 05-18-2008, 05:48 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 3,185
Default

This is an example of drawing thick lines:
Code:
Sub Globals
    Dim Type(x,y) points(0)
End Sub

Sub App_Start
    Form1.Show
    DrawThickLine ("Form1",20,30,20,200,10,cGold)
    DrawThickLine ("Form1",20,30,70,44,10,cRed)
End Sub

Sub DrawThickLine(Form, x1, y1, x2, y2, width, color)
    l = ATan((y2-y1)/(x2-x1+0.01))
    dx = width/2 * Sin(l)
    dy = width/2 * Cos(l)
    points() = Array((x1 + dx,y1 - dy),(x2 + dx,y2 - dy), _
                (x2 - dx,y2 + dy),(x1 - dx,y1 + dy))
    Control(Form,Form).Polygon(points(),0,4,color,f)
End Sub
Reply With Quote
  #4 (permalink)  
Old 08-20-2008, 11:52 AM
Senior Member
 
Join Date: Apr 2008
Location: Gosford NSW Australia
Posts: 127
Send a message via MSN to tsteward
Default

Quote:
Originally Posted by Erel View Post
This is an example of drawing thick lines:
Code:
Sub Globals
    Dim Type(x,y) points(0)
End Sub

Sub App_Start
    Form1.Show
    DrawThickLine ("Form1",20,30,20,200,10,cGold)
    DrawThickLine ("Form1",20,30,70,44,10,cRed)
End Sub

Sub DrawThickLine(Form, x1, y1, x2, y2, width, color)
    l = ATan((y2-y1)/(x2-x1+0.01))
    dx = width/2 * Sin(l)
    dy = width/2 * Cos(l)
    points() = Array((x1 + dx,y1 - dy),(x2 + dx,y2 - dy), _
                (x2 - dx,y2 + dy),(x1 - dx,y1 + dy))
    Control(Form,Form).Polygon(points(),0,4,color,f)
End Sub
Hey this is pretty good. Thanks Erel.
Now the maths in the above routine is way over my head but, the lines are not very smooth.
Can anyone improve this?
Please
Or is this as good as it gets?

Thanks
Tony
Reply With Quote
  #5 (permalink)  
Old 08-20-2008, 02:39 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Switzerland
Posts: 702
Awards Showcase
Beta Tester Competition Winner 
Total Awards: 2
Default

Add the red line and you will have smouth lines with rounded ends.

Code:
Sub Globals
    Dim Type(x,y) points(0)
End Sub

Sub App_Start
    Form1.Show
    DrawThickLine ("Form1",20,30,20,200,10,cGold)
    DrawThickLine ("Form1",20,30,70,44,10,cRed)
End Sub

Sub DrawThickLine(Form, x1, y1, x2, y2, width, color)
    l = ATan((y2-y1)/(x2-x1+0.01))
    dx = width/2 * Sin(l)
    dy = width/2 * Cos(l)
    points() = Array((x1 + dx,y1 - dy),(x2 + dx,y2 - dy), _
                (x2 - dx,y2 + dy),(x1 - dx,y1 + dy))
    Control(Form,Form).Polygon(points(),0,4,color,f)
    Control(Form,Form).Circle(x1,y1,penWidth/2,Pencolour,f)
End Sub
Best regards.
__________________
Klaus
Switzerland
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Travian off-line stats... Cableguy Questions & Help Needed 3 07-25-2008 05:55 AM
FileWrite at certain line..? TWELVE Questions & Help Needed 2 05-13-2008 06:29 AM
Error at line 0? Mistrel Questions & Help Needed 9 11-04-2007 08:40 PM
Error when using an array of types zurpa Questions & Help Needed 5 10-27-2007 09:19 PM
How to draw a line? RandomCoder Questions & Help Needed 3 08-24-2007 10:11 PM


All times are GMT. The time now is 02:40 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0