B4J Question How to invalidate pane in B4J (xui)?

Meigionel TS

Member
Licensed User
I have started to port B4A code to B4J and used xui to do so. But in the B4A code I had an option to invalidate a view, or invalidate2 and invalidate3 to redraw panels in B4A. But when I started to convert the code to b4x, I found that B4X view or Pane view does not provide any option to redraw the panels or the B4Xrect inside them? Do anyone know how to do it?
 

Erel

Administrator
Staff member
Licensed User
The only case where views need to be invalidated is when you draw over them with Canvas / B4XCanvas. Is this the case here?
 

Erel

Administrator
Staff member
Licensed User
B4XCanvas.Invalidate. Note that it doesn't do anything in B4J.
 

Meigionel TS

Member
Licensed User
But what I need is for B4J, I have used invalidate and invalidate2 with regular canvas in some major work in a B4A project, but now I have to move the project to B4J, and now I cannot find out how to perform the same thing in B4J. As there is no member called invalidate in B4J? If I would want this action to be performed in B4J, how can I do that?
 

Erel

Administrator
Staff member
Licensed User
You should switch to B4XCanvas and use the exact same code in all platforms. You need to call B4XCanvas.Invalidate when you are done drawing. It doesn't do anything in B4J because it is not required. The drawings will appear.
 

Meigionel TS

Member
Licensed User
Also here is a snippet of what I used to do in B4A.

B4X:
Private Sub DrawCursor
    Private dc = 7dip As Int
    Private Radius = 3dip As Int
    Private X = XTicks(CurrentX(GI)) As Int
    Private Y = ValueToPixels(CurrentY(GI)) As Int
    Private Y2 = ValueToPixels(CurrentY2(GI)) As Int
    
    cvsCursor(GI).DrawRect(rectCursor(GI), Colors.Transparent, True, 1dip)
    cvsCursor(GI).DrawRect(rectCursor2(GI), Colors.Transparent, True, 1dip)
    pnlCursor(GI).Invalidate2(rectCursor(GI))
    pnlCursor(GI).Invalidate2(rectCursor2(GI))
    If GI == 1 Then
        cvsCursor(GI).DrawLine(X - dc, Y, X + dc, Y, Colors.Red, 2dip)
        cvsCursor(GI).DrawLine(X, Y - dc, X, Y + dc, Colors.Red, 2dip)
    End If
    If GI == 0 Then
        cvsCursor(GI).DrawLine(X - dc, Y, X + dc, Y, Colors.Blue, 2dip)
        cvsCursor(GI).DrawLine(X, Y - dc, X, Y + dc, Colors.Blue, 2dip)
    End If
    rectCursor(GI).Initialize(X - dc, Y - dc, X + dc, Y + dc)
    pnlCursor(GI).Invalidate2(rectCursor(GI))
    
    cvsCursor(GI).DrawCircle(X, Y2, Radius, Colors.Black, True, 1dip)
    rectCursor2(GI).Initialize(X - Radius, Y2 - Radius, X + Radius, Y2 + Radius)
    pnlCursor(GI).Invalidate2(rectCursor2(GI))
    
    
End Sub
Please help me convert this code to B4J.
 

Erel

Administrator
Staff member
Licensed User
Start with switching to B4XCanvas and call cvsCursor(GI).Invalidate instead of pnlCursor(GI).Invalidate.
 

Meigionel TS

Member
Licensed User
It doesn't do anything in B4J because it is not required. The drawings will appear.
But it seems like it is required in B4J, because though the drawings will appear but there won't be a way to redraw something, once it is drawn how can you change it? Or I mean, remove the former drawing and redraw it again?
 

Meigionel TS

Member
Licensed User
Okay, right.
ClearRect
This seem to do what I wanted. But there is some kind of strange left-over when I am trying to clear the previous rects, it is clearing most of what is drawn but it is leavin behind some very small parts of what has been drawn.

Please see the attached video, I am pointing the problem with my mouse cursor.

 

klaus

Expert
Licensed User
There is a big difference between B4J and B4A/B4i.
Drawing with a transparent color does nothing in B4J.
In B4A/B4i, drawing with a tranparent color sets the background color to tranparent which is not the case in B4J.
 

Erel

Administrator
Staff member
Licensed User
The simplest solution is to clear the complete canvas: cvs.ClearRect(cvs.TargetRect)

If you want to keep the grid then either draw it each time or use two layers (two panels).
 
Top