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

Discussion in 'B4J Questions' started by Meigionel TS, Jun 21, 2018.

Tags:
  1. Meigionel TS

    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?
     
  2. Erel

    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?
     
  3. Meigionel TS

    Meigionel TS Member Licensed User

    Yes. I am using B4XCanvas to draw over it.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    B4XCanvas.Invalidate. Note that it doesn't do anything in B4J.
     
  5. Meigionel TS

    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?
     
  6. Erel

    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 likes this.
  7. Meigionel TS

    Meigionel TS Member Licensed User

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

    Code:
    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, True1dip)
        cvsCursor(GI).DrawRect(rectCursor2(GI), 
    Colors.Transparent, True1dip)
        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, True1dip)
        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.
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Start with switching to B4XCanvas and call cvsCursor(GI).Invalidate instead of pnlCursor(GI).Invalidate.
     
  9. Meigionel TS

    Meigionel TS Member Licensed User

    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?
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    Invalidate has nothing to do with redrawing. Not in B4J and not in B4A.
    You can use ClearRect or FillRect to "erase" previous drawings.
     
    Meigionel TS likes this.
  11. Meigionel TS

    Meigionel TS Member Licensed User

    Okay, right.
    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.

     
  12. Meigionel TS

    Meigionel TS Member Licensed User

    This are the left over after I try to clearrect.
     

    Attached Files:

  13. klaus

    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.
     
    Meigionel TS and Erel like this.
  14. Erel

    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).
     
    Meigionel TS likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice