DrawingArea.Refresh erases the DrawingArea

Post your Gambas programming questions here.
Post Reply
Zeke99
Posts: 12
Joined: Tuesday 12th January 2021 7:44pm

DrawingArea.Refresh erases the DrawingArea

Post by Zeke99 »

This is what I'm trying to achive:

I have a drawingarea 900 pixels wide (and 20 pixels high) and a timer that triggers every 5 seconds. Every time the timer trigger it checks the status of three radiobuttons and make a vertical line in the drawingarea with grey, red or green color depending on which radiobutton that is active. It's like a progressbar but with the possibility to see the status of the radiobuttons over time.
The problem is that when I do the drawingarea.refresh it erases the previous lines.

The code:
Public StatusValue1 As Byte

Public Sub DrawingArea1_Draw()

  Select Case StatusValue1
    Case 0
      Paint.Brush = Paint.Color(Color.LightGray)      
    Case 1
      Paint.Brush = Paint.Color(Color.Red)  
    Case 2
      Paint.Brush = Paint.Color(Color.Green)          
  End Select
  Paint.LineWidth = 1
  Paint.MoveTo(CInt(Timer), 0)
  Paint.LineTo(CInt(Timer), 20)
  Paint.Stroke
  
End

Public Sub Timer1_Timer()

  StatusValue1 = 0
  
  If RadioButton2.Value = True Then 
   StatusValue1 = 1
  Else 
    If RadioButton3.Value = True Then 
      StatusValue1 = 2
    Endif 
  Endif 
  
  DrawingArea1.Refresh
End

The Drawingarea.cached is false (if it's true the drawingarea_draw-event will not trigger).

I admit that my knowledge and experience of graphics and the drawingarea functions is very slim. Can anyone point out what I'm doing wrong or have a link to an example?
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: DrawingArea.Refresh erases the DrawingArea

Post by BruceSteers »

Yes the Refresh redraws the DrawingArea form blank.

you need to draw all 3 lines in the _Draw() event and make their color show per setting.
If at first you don't succeed , try doing something differently.
BruceS
Zeke99
Posts: 12
Joined: Tuesday 12th January 2021 7:44pm

Re: DrawingArea.Refresh erases the DrawingArea

Post by Zeke99 »

Thanks a lot for the answer, Bruce.

This is for monitoring CNC-machines and their performance.
8 machines, 17 hours a day with an check-interval of 15 seconds then I will have to draw up to 32640 lines every 15 seconds at the end of the day. I wonder how fast gambas is on a pi?

Ok, back to the drawing board. Maybe test manipulating an image instead? If anyone have an example of manipulating pixels in an image please let me know.
vuott
Posts: 263
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: DrawingArea.Refresh erases the DrawingArea

Post by vuott »

I would use :? arrays for color and lines.
Private lines As New Float[]
Private colores As New Integer[]
Private StatusValue1 As Byte


Public Sub Form_Open()

  Timer1.Delay = 15000
  Timer1.Start

End


Public Sub DrawingArea1_Draw()
 
  If lines.Count == 0 Then Return 
 
  Select Case StatusValue1
    Case 0
      colores.Push(Color.LightGray)
    Case 1
      colores.Push(Color.Red)
    Case 2
      colores.Push(Color.Green)
  End Select


  Paint.LineWidth = 1
  For c As Short = 0 To lines.Max
    Paint.Brush = Paint.Color(colores[c])
    Paint.MoveTo(lines[c], 0)
    Paint.LineTo(lines[c], 20)
    Paint.Stroke
  Next 

End
 
Public Sub Timer1_Timer()
 
  StatusValue1 = 0
   
  If RadioButton1.Value = True Then 
   StatusValue1 = 1
  Else 
    If RadioButton2.Value = True Then 
      StatusValue1 = 2
    Endif 
  Endif 
  lines.Push(Timer)
  DrawingArea1.Refresh
  
End
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: DrawingArea.Refresh erases the DrawingArea

Post by BruceSteers »

Well the code for MediaPlayer is a DrawingArea that refreshes a whole video screen at x-frames per second.

A DrawingArea is used in a lot of gambas controls,
Paint.class is pretty darn fast :)

A simple drawing of three lines is nothing :)
If at first you don't succeed , try doing something differently.
BruceS
vuott
Posts: 263
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: DrawingArea.Refresh erases the DrawingArea

Post by vuott »

Zeke99 wrote: Sunday 19th November 2023 9:59pm If anyone have an example of manipulating pixels in an image please let me know.
Perhaps :? this page can help you a little:
https://www.gambas-it.org/wiki/index.ph ... ory_Stream
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
Zeke99
Posts: 12
Joined: Tuesday 12th January 2021 7:44pm

Re: DrawingArea.Refresh erases the DrawingArea

Post by Zeke99 »

I tested to do an array and draw the whole drawingarea yesterday and it worked. Now it's just to scale it up, move to the Raspberry pi and test if it lags or not.
Have a pi 3B+. If it isn't fast enough I can always buy a pi 5.

Vuott, thank's for the link to the example with the pixel manipulation of a picture. My knowledge of the italian language is a bit limited (count from 1 to twelve) but I think I got the hang of it. Will test that too even if it works with the drawingarea and paint.

Again, thank's a lot for the support!
vuott
Posts: 263
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: DrawingArea.Refresh erases the DrawingArea

Post by vuott »

Zeke99 wrote: Monday 20th November 2023 8:41pm My knowledge of the italian language is a bit limited (count from 1 to twelve) but I think I got the hang of it.
You can use a translator on-line, for example:
https://www.deepl.com/en/translator
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
User avatar
BruceSteers
Posts: 1579
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: DrawingArea.Refresh erases the DrawingArea

Post by BruceSteers »

It occurred to me you might not need to use DrawingArea.Refresh as this refreshes the whole thing.
You might be able to just paint direct using Paint (possibly this is what you wanted)

Something like this.......

Public StatusValue1 As Byte

Public Sub Timer1_Timer()

  StatusValue1 = 0
  
  If RadioButton2.Value = True Then 
   StatusValue1 = 1
  Else 
    If RadioButton3.Value = True Then 
      StatusValue1 = 2
    Endif 
  Endif 
  
  Paint.Begin(DrawingArea1)  
  Select Case StatusValue1
    Case 0
      Paint.Brush = Paint.Color(Color.LightGray)      
    Case 1
      Paint.Brush = Paint.Color(Color.Red)  
    Case 2
      Paint.Brush = Paint.Color(Color.Green)          
  End Select
  Paint.LineWidth = 1
  Paint.MoveTo(CInt(Timer), 0)
  Paint.LineTo(CInt(Timer), 20)
  Paint.Stroke
  Paint.End

End


That way should paint direct on the Drawingarea and not refresh it

Just a thought
If at first you don't succeed , try doing something differently.
BruceS
Post Reply