DrawRect doesn't always draw

aemedwedew

New Member
Licensed User
Longtime User
Coordinates to the right and below the screen will not display using DrawRect. Is this a bug?


'Activity module
Sub Process_Globals
End Sub

Sub Globals
Type CDI_DDD_POINT(x As Float, y As Float, z As Float)

Dim ScreenExtents As Float
Dim pnlCursor As Panel
Dim pnlDrawing As Panel
Dim rectPanels As Rect
Dim DrawingCanvas As Canvas
Dim CursorCanvas As Canvas
Dim cx1 As Float
Dim cy1 As Float
Dim cx2 As Float
Dim cy2 As Float

ScreenExtents=1280
End Sub

Sub Activity_Create(FirstTime As Boolean)
pnlDrawing.Initialize("pnlDrawing")
Activity.AddView(pnlDrawing, 0, 0, ScreenExtents, ScreenExtents)
rectPanels.Initialize(0, 0, pnlDrawing.Width, pnlDrawing.Height)
DrawingCanvas.Initialize(pnlDrawing)

pnlCursor.Initialize("pnlCursor")
Activity.AddView(pnlCursor, 0, 0 , ScreenExtents, ScreenExtents)
rectPanels.Initialize(0, 0, pnlCursor.Width, pnlCursor.Height)
CursorCanvas.Initialize(pnlCursor)

Dim r As Rect
r.Initialize(0, 0, 100%x, 100%y)
DrawingCanvas.DrawRECT(r, Colors.Transparent, True, 0)
pnlDrawing.Invalidate

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
Select Case KeyCode
Case KeyCodes.KEYCODE_BACK

Return True

Case Else
Return False

End Select
End Sub

Sub DrawRECT(cnvs As Canvas, px1 As Float, py1 As Float, px2 As Float,py2 As Float, color As Int, weight As Int)
Dim Rect1 As Rect
Rect1.Initialize(px1, py1, px2, py2)
cnvs.DrawRECT(Rect1, color, False, weight)
pnlDrawing.Invalidate
End Sub

Sub pnlCursor_Touch(Action As Int, x As Float, y As Float)
Dim CurrentLineColor As Int
Dim CurrentLineWeight As Int
Dim CurrentCursorColor As Int
Dim Rect1 As Rect
Dim MirrorPoint As CDI_DDD_POINT

CurrentLineColor=Colors.ARGB(255,255,255,255)
CurrentLineWeight=25
CurrentCursorColor=Colors.Green

Select Action
Case Activity.ACTION_DOWN
cx1 = x
cy1 = y
cx2 = x
cy2 = y

Case Activity.ACTION_MOVE
CursorCanvas.DrawLINE(cx1, cy1, cx2, cy2, Colors.Transparent, CurrentLineWeight)
MirrorPoint=GetMirrorPoint(cx1, cy1, 0, cx2, cy2, 0)
CursorCanvas.DrawLINE(cx1, cy1, cx1, MirrorPoint.y, Colors.Transparent, CurrentLineWeight)
Rect1.Initialize(MirrorPoint.x, MirrorPoint.y, cx2, cy2)
CursorCanvas.DrawRECT(Rect1, Colors.Transparent, False, CurrentLineWeight)
pnlCursor.Invalidate
cx2 = x
cy2 = y
CursorCanvas.DrawLINE(cx1, cy1, cx2, cy2, CurrentCursorColor, CurrentLineWeight)
MirrorPoint=GetMirrorPoint(cx1, cy1, 0, cx2, cy2, 0)
CursorCanvas.DrawLINE(cx1, cy1, cx1, MirrorPoint.y, CurrentCursorColor, CurrentLineWeight)
Rect1.Initialize(MirrorPoint.x, MirrorPoint.y, cx2, cy2)
CursorCanvas.DrawRECT(Rect1, CurrentCursorColor , False, CurrentLineWeight)
pnlCursor.Invalidate

Case Activity.ACTION_UP
CursorCanvas.DrawLINE(cx1, cy1, cx2, cy2, Colors.Transparent, CurrentLineWeight)
MirrorPoint=GetMirrorPoint(cx1, cy1, 0, cx2, cy2, 0)
CursorCanvas.DrawLINE(cx1, cy1, cx1, MirrorPoint.y, Colors.Transparent, CurrentLineWeight)
Rect1.Initialize(MirrorPoint.x, MirrorPoint.y, cx2, cy2)
CursorCanvas.DrawRECT(Rect1, Colors.Transparent, False, CurrentLineWeight)
pnlCursor.Invalidate
MirrorPoint=GetMirrorPoint(cx1, cy1, 0, x, y, 0)
Rect1.Initialize(MirrorPoint.x, MirrorPoint.y, x, y)

DrawRECT(DrawingCanvas, MirrorPoint.x, MirrorPoint.y, x, y, CurrentLineColor, CurrentLineWeight)
pnlCursor.Invalidate

End Select

End Sub

Sub GetMirrorPoint(pnt0x As Float, pnt0y As Float, pnt0z As Float, pnt1x As Float, pnt1y As Float, pnt1z As Float) As CDI_DDD_POINT
Dim result As CDI_DDD_POINT
result.x = pnt0x - (pnt1x - pnt0x)
result.y = pnt0y - (pnt1y - pnt0y)
result.z = pnt0z - (pnt1z - pnt0z)
Return result
End Sub

Sub AddWebView(x1 As Float, y1 As Float,x2 As Float, y2 As Float)
pnlDrawing.AddView(MakeWebView("http://nycissues.org"),x1,y1,x2,y2)

End Sub

Sub MakeWebView(URL As String) As WebView
Dim TempWebView As WebView
TempWebView.Initialize("TempWebView")
TempWebView.LoadUrl(URL)
Return TempWebView
End Sub
 

aemedwedew

New Member
Licensed User
Longtime User
The example I posted demonstrates Drawrect not drawing a rectangle when one of the coordinates is beyond the right or bottom areas of the screen. Using the DrawLine method does not have a problem using the same coordinates. When running the code I posted on a Google Nexus 7 starting, a swipe of the screen from the lower right and ending the upper left creates a cursor and rectangle being drawn. When the rectangle being continuosly drawn reaches a certain size it disappears, where the line being drawn doesn't.
 

aemedwedew

New Member
Licensed User
Longtime User
Rect1 does not draw. Coordinates might need to be in smallest forder.

Dim pnlCursor As Panel
Dim pnlDrawing As Panel
Dim rectPanels As Rect
Dim DrawingCanvas As Canvas
Dim CursorCanvas As Canvas

pnlDrawing.Initialize("pnlDrawing")
Activity.AddView(pnlDrawing, 0, 0, 1280, 1280)
rectPanels.Initialize(0, 0, pnlDrawing.Width, pnlDrawing.Height)
DrawingCanvas.Initialize(pnlDrawing)

pnlCursor.Initialize("pnlCursor")
Activity.AddView(pnlCursor, 0, 0 , 1280, 1280)
rectPanels.Initialize(0, 0, pnlCursor.Width, pnlCursor.Height)
CursorCanvas.Initialize(pnlCursor)

Dim r As Rect
r.Initialize(0, 0, 100%x, 100%y)
DrawingCanvas.DrawRECT(r, Colors.Transparent, True, 0)
pnlDrawing.Invalidate

Dim Rect1 As Rect
Rect1.Initialize(993,1490,320,700)
CursorCanvas.DrawRECT(Rect1, Colors.Green , False, 10)

Dim Rect2 As Rect
Rect2.Initialize(300,690,993,1490)
CursorCanvas.DrawRECT(Rect2, Colors.red , False, 10)

Dim Rect3 As Rect
Rect3.Initialize(90,130,20,70)
CursorCanvas.DrawRECT(Rect3, Colors.cyan , False, 10)

Dim Rect4 As Rect
Rect4.Initialize(130,160,220,370)
CursorCanvas.DrawRECT(Rect4, Colors.Magenta , False, 10)

CursorCanvas.DrawLine(993, 1490, 320, 700, Colors.Blue, 10)
CursorCanvas.DrawLine(270, 300, 995, 1590, Colors.Yellow, 10)
 

Bob Sabrook

Member
Licensed User
Longtime User
When you define the rectangle used by DrawRect the problem will not occur if you ensure that Y1<y2 like this

Rect1.Initialize( x1 ,min(y1,y2), x2, max(y1,y2) )
 

Attachments

  • B4a_Clip.zip
    13 KB · Views: 222
Top