Edit a 2D line...
Blitz3D Forums/Blitz3D Beginners Area/Edit a 2D line...
| ||
Is it possible to select a 2D line and edit it's properties like start point, end point, length, color, etc? If so, how? Here is my sample code. I would appreciate any point in the right direction. Thanks, David Graphics 1200,900,16 Type MyLines Field SX# ;LINE START POINT X Field SY# ;LINE START POINT Y Field EX# ;LINE END POINT X Field EY# ;LINE END POINT Y Field LColor$ ;LINE COLOR Field LName$ ;LINE NAME End Type X = 200 Y = 200 fntArial=LoadFont("Calibri",10,False,False,False) SetFont fntArial For I = 1 To 5 gl.MyLines = New MyLines gl\LName$ = "Line_" + I gl\SX# = X gl\SY# = Y + I * 50 gl\EX# = X + 400 gl\EY# = Y + I * 50 If I = 1 Or I = 3 Or I = 5 Then gl\LColor$ = "RED" Else gl\LColor$ = "White" End If Next ; Wait for ESC to hit While Not KeyHit(1) SetBuffer BackBuffer() Cls For gl.MyLines = Each MyLines Select gl\LColor$ Case "RED" Color 255,0,0 Default Color 255,255,255 End Select Oval gl\SX#, gl\SY# - 2, 4, 4, 1 Line(gl\SX#, gl\SY#, gl\EX#, gl\EY#) Oval gl\EX#, gl\EY# - 2, 4, 4, 1 Text gl\EX# + 10, gl\EY#-5, Abs(gl\SX# - gl\EX#) Color 255,255,0 Line MouseX(), 0, MouseX(),GraphicsHeight() Line 0, MouseY(), GraphicsWidth(), MouseY() HidePointer Next Flip Wend |
| ||
To define a point position you could detect when the cursor is over a point (in a certain range) by calculating if the cursor coordinates (X%,Y%) is inside an area coordinates around the point (between pointX%-3,pointY%-3 and pointX%+3,PointY%+3) and if yes, and if the user is holding the mousebutton, set the state of the point to "edit", and when in state "edit", the point would be positionned at the cursor position, and when the user releases the mousebutton, position the point at the cursor position and set the state of the point to "set". (also have a variable to make sure that the user can only edit only one point at a time) To define the color of a line you could first select a line with the mouse wheel or by picking it (check if the mouse cursor is over a line after a mouseclick), and then ask the user which color he wants to use (with a string like "255,255,255" of by picking a color on a premade image that you would display. To ask the user for the color with a string, you may want to use this : http://www.blitzbasic.com/codearcs/codearcs.php?code=3262 Good luck, |
| ||
Thanks for the good ideas. I'll give them a try. |