DrawingArea.Refresh erases the DrawingArea

Post

Posted
Rating:
#1 (In Topic #1136)
Trainee
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:

Code (gambas)

  1. Public StatusValue1 As Byte
  2.  
  3. Public Sub DrawingArea1_Draw()
  4.  
  5.   Select Case StatusValue1
  6.     Case 0
  7.       Paint.Brush = Paint.Color(Color.LightGray)      
  8.     Case 1
  9.       Paint.Brush = Paint.Color(Color.Red)  
  10.     Case 2
  11.       Paint.Brush = Paint.Color(Color.Green)          
  12.   Paint.LineWidth = 1
  13.   Paint.MoveTo(CInt(Timer), 0)
  14.   Paint.LineTo(CInt(Timer), 20)
  15.   Paint.Stroke
  16.  
  17.  
  18. Public Sub Timer1_Timer()
  19.  
  20.   StatusValue1 = 0
  21.  
  22.   If RadioButton2.Value = True Then
  23.    StatusValue1 = 1
  24.   Else
  25.     If RadioButton3.Value = True Then
  26.       StatusValue1 = 2
  27.     Endif
  28.   Endif
  29.  
  30.   DrawingArea1.Refresh
  31.  
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?
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
 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.
Online now: No Back to the top

Post

Posted
Rating:
#3
Trainee
 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.
Online now: No Back to the top

Post

Posted
Rating:
#4
Regular
vuott is in the usergroup ‘Regular’
I would use :? arrays for color and lines.

Code (gambas)

  1. Private colores As New Integer[]
  2. Private StatusValue1 As Byte
  3.  
  4.  
  5. Public Sub Form_Open()
  6.  
  7.   Timer1.Delay = 15000
  8.   Timer1.Start
  9.  
  10.  
  11.  
  12. Public Sub DrawingArea1_Draw()
  13.  
  14.   If lines.Count == 0 Then Return
  15.  
  16.   Select Case StatusValue1
  17.     Case 0
  18.       colores.Push(Color.LightGray)
  19.     Case 1
  20.       colores.Push(Color.Red)
  21.     Case 2
  22.       colores.Push(Color.Green)
  23.  
  24.  
  25.   Paint.LineWidth = 1
  26.   For c As Short = 0 To lines.Max
  27.     Paint.Brush = Paint.Color(colores[c])
  28.     Paint.MoveTo(lines[c], 0)
  29.     Paint.LineTo(lines[c], 20)
  30.     Paint.Stroke
  31.   Next
  32.  
  33.  
  34. Public Sub Timer1_Timer()
  35.  
  36.   StatusValue1 = 0
  37.    
  38.   If RadioButton1.Value = True Then
  39.    StatusValue1 = 1
  40.   Else
  41.     If RadioButton2.Value = True Then
  42.       StatusValue1 = 2
  43.     Endif
  44.   Endif
  45.   lines.Push(Timer)
  46.   DrawingArea1.Refresh
  47.  

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’
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 :)
Online now: No Back to the top

Post

Posted
Rating:
#6
Regular
vuott is in the usergroup ‘Regular’

Zeke99 said

If anyone have an example of manipulating pixels in an image please let me know.
Perhaps :? this page can help you a little:
Modificare i colori dei pixel di un'immagine con la proprietà .Data della Classe Image ed i Memory Stream - Gambas-it.org - Wikipedia

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#7
Trainee
 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!
Online now: No Back to the top

Post

Posted
Rating:
#8
Regular
vuott is in the usergroup ‘Regular’

Zeke99 said

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:
DeepL Translate: The world's most accurate translator

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#9
Guru
BruceSteers is in the usergroup ‘Guru’
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…….

Code (gambas)

  1. Public StatusValue1 As Byte
  2.  
  3. Public Sub Timer1_Timer()
  4.  
  5.   StatusValue1 = 0
  6.  
  7.   If RadioButton2.Value = True Then
  8.    StatusValue1 = 1
  9.   Else
  10.     If RadioButton3.Value = True Then
  11.       StatusValue1 = 2
  12.     Endif
  13.   Endif
  14.  
  15.   Paint.Begin(DrawingArea1)  
  16.   Select Case StatusValue1
  17.     Case 0
  18.       Paint.Brush = Paint.Color(Color.LightGray)      
  19.     Case 1
  20.       Paint.Brush = Paint.Color(Color.Red)  
  21.     Case 2
  22.       Paint.Brush = Paint.Color(Color.Green)          
  23.   Paint.LineWidth = 1
  24.   Paint.MoveTo(CInt(Timer), 0)
  25.   Paint.LineTo(CInt(Timer), 20)
  26.   Paint.Stroke
  27.   Paint.End
  28.  
  29.  

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

Just a thought
Online now: No Back to the top
1 guest and 0 members have just viewed this.