ProgressBar Text colour

Post

Posted
Rating:
#1 (In Topic #2073)
Avatar
Enthusiast
Yogi is in the usergroup ‘Enthusiast’
Hi folks,

Just want to know if there is the possibility to change the progressbars text colour?


Code (gambas)

Progressbar1.text="TEST"

the background and foreground colour is for the progressbar progress…

Just used it in the mp3 Player and maybe who tested it and has a Gambas Version prior 3.20 will get an error
because it exists since 3.20 …

Thanks,
Regards
Yogi
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Administrator
gbWilly is in the usergroup ‘unknown’
gbWilly is in the usergroup ‘Blogger’
gbWilly is in the usergroup ‘GambOS Developer’

Yogi said

the background and foreground colour is for the progressbar progress…
There is your answer and there are no other properties for that

gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories


… there is always a Catch if things go wrong!
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Enthusiast
Yogi is in the usergroup ‘Enthusiast’

gbWilly said

Yogi said

the background and foreground colour is for the progressbar progress…
There is your answer and there are no other properties for that


Would be a nice feature!
Thanks!
Regards,
Yogi
Online now: No Back to the top

Post

Posted
Rating:
#4
Avatar
Enthusiast
Yogi is in the usergroup ‘Enthusiast’
Hi,
I have no idea if it would be better to inherit from the progressbar class for the text colour of the progressbar.

I copied the progressbar class in my project folder and renamed it. And enhanced the class
with the property and the private variable:

Code (gambas)

Property TextColor As Integer
Private $sTextColor As Integer
 

So now if the 'progressbar1.text="TEST" ' and
'progressbar1.textColor=COLOR.RED'
is set, the text appears red.

progressbar1 has to be the new renamed progressbar class,
here we go:

Code (gambas)

  1. ' Gambas class file
  2.  
  3.  
  4. Inherits UserControl
  5.  
  6. Public Const _Properties As String = "*,Action,Label=True,Border=True,Pulse"
  7. Public Const _Group As String = "Form"
  8. Public Const _DefaultEvent As String = "MouseDown"
  9. Public Const _DefaultSize As String = "24,4"
  10.  
  11.  
  12. '' @{since 3.20}
  13. '' Return or set the text displayed in the progress bar.
  14. ''
  15. '' If not set, which is the default, the value property is displayed as a percentage.
  16.  
  17. '---- INSERTED ---------------------
  18. Property TextColor As Integer
  19.  
  20. Private $sTextColor As Integer
  21. '------------------------------------------
  22.  
  23. Private $fValue As Float
  24. Private $hTimerPulse As Timer
  25. Private $bBorder As Boolean = True
  26.  
  27. Private Function Label_Read() As Boolean
  28.  
  29.   Return $bLabel
  30.  
  31.  
  32. Private Sub Label_Write(Value As Boolean)
  33.  
  34.   $bLabel = Value
  35.   Me.Refresh
  36.  
  37.  
  38. Private Function Value_Read() As Float
  39.  
  40.   If $bPulse Then Return
  41.   Return $fValue
  42.  
  43.  
  44. Private Sub Value_Write(Value As Float)
  45.  
  46.   If $bPulse Then Return
  47.  
  48.   Value = Max(0, Min(1, Value))
  49.   If Value = $fValue Then Return
  50.   $fValue = Value
  51.  
  52.   Me.Refresh
  53.  
  54.  
  55. Public Sub UserControl_Draw()
  56.  
  57.   Dim W As Float
  58.   Dim iCol As Integer
  59.   Dim sText As String
  60.   Dim HP, WP As Integer
  61.  
  62. ' INSERTED-----------------------------------
  63. 'Give the default Colour  
  64.   If $sTextColor = Null Then
  65.     $sTextColor = Color.Foreground
  66. '---------------------------------------------------
  67.  
  68.   If $bBorder Then
  69.     Style.PaintBackground(0, 0, Paint.W, Paint.H, Me.Background)
  70.     Style.ClipBackground(0, 0, Paint.W, Paint.H)
  71.     'F = Style.BorderSize
  72.  
  73.   iCol = Color.SetAlpha(Color.SelectedBackground, 160)
  74.   If Not Me.Enabled Then iCol = Color.Desaturate(iCol)
  75.  
  76.   'Draw.Foreground = Color.LightForeground
  77.   'Draw.Rect(0, 0, Paint.W, Paint.H)
  78.  
  79.   'Style.PaintPanel(0, 0, Paint.W, Paint.H, Border.Sunken)
  80.  
  81.   'Paint.Rectangle(F, F, Paint.W - F * 2, Paint.H - F * 2, DS - F)
  82.   'Paint.Clip
  83.  
  84.   If $bPulse Then
  85.    
  86.     HP = Paint.H
  87.     WP = Min(Paint.H, Desktop.Scale * 8)
  88.     $iPulse = $iPulse Mod (WP * 2)
  89.    
  90.     Paint.Save
  91.     Paint.Background = iCol
  92.     Paint.Translate($iPulse - (HP + WP) * 2, 0)
  93.     For I = 0 To Paint.W + (HP + WP) * 2 Step WP * 2
  94.       Paint.MoveTo(0, HP)
  95.       Paint.LineTo(HP, 0)
  96.       Paint.LineTo(WP + HP, 0)
  97.       Paint.LineTo(WP, HP)
  98.       Paint.LineTo(0, HP)
  99.       Paint.Fill
  100.       Paint.Translate(WP * 2, 0)
  101.     Next
  102.     Paint.Restore
  103.    
  104.     sText = $sText
  105.     Paint.Background = Color.SelectedBackground
  106.     Paint.DrawTextShadow(sText, 0, 0, Paint.W, Paint.H, Align.Center, 1)    
  107.     Paint.Background = Color.Foreground
  108.     GoSub DRAW_LABEL
  109.    
  110.   Else
  111.  
  112.     W = Paint.W * $fValue
  113.  
  114.     sText = $sText
  115.     If Not sText Then sText = Format($fValue, "0%")
  116.  
  117.     If Me.RightToLeft Then
  118.      
  119.       Paint.FillRect(Paint.W - W, 0, W, Paint.H, iCol)
  120.      
  121.       If $bLabel Then
  122.    
  123.         ' Paint.Save
  124.         ' Paint.Rectangle(Paint.W - W, 0, W, Paint.H)
  125.         ' Paint.Clip
  126.         ' Paint.Background = Color.SelectedForeground
  127.         ' GoSub DRAW_LABEL
  128.         ' Paint.Restore
  129.    
  130.         'Paint.Save
  131.         'Paint.Rectangle(0, 0, Paint.W - W, Paint.H)
  132.         'Paint.Clip
  133.         Paint.Background = Color.Foreground
  134.         GoSub DRAW_LABEL
  135.         'Paint.Restore
  136.    
  137.       Endif
  138.      
  139.     Else
  140.      
  141.       Paint.FillRect(0, 0, W, Paint.H, iCol)
  142.    
  143.       If $bLabel Then
  144.    
  145.         ' Paint.Save
  146.         ' Paint.Rectangle(0, 0, W, Paint.H)
  147.         ' Paint.Clip
  148.         ' Paint.Background = Color.SelectedForeground
  149.         ' GoSub DRAW_LABEL
  150.         ' Paint.Restore
  151.    
  152.         'Paint.Save
  153.         'Paint.Rectangle(W, 0, Paint.W - W, Paint.H)
  154.         'Paint.Clip
  155.         Paint.Background = Color.Foreground
  156.         GoSub DRAW_LABEL
  157.         'Paint.Restore
  158.    
  159.       Endif
  160.      
  161.     Endif
  162.    
  163.  
  164.   Return
  165.  
  166. DRAW_LABEL:
  167. '---- CHANGED -----------------------------
  168.  Paint.Background = $sTextColor
  169. '--------------------------------------------------
  170.  
  171.   If sText Then Paint.DrawText(sText, 0, 0, Paint.W, Paint.H, Align.Center)    
  172.   Return
  173.  
  174.  
  175.  
  176. Private Function Pulse_Read() As Boolean
  177.  
  178.   Return $bPulse
  179.  
  180.  
  181. Private Sub Pulse_Write(Value As Boolean)
  182.  
  183.   If Value = $bPulse Then Return
  184.  
  185.   $bPulse = Value
  186.  
  187.   If Me.Design Then Return
  188.  
  189.   If $bPulse And If Me.W > (Me.H * 2) Then
  190.     $hTimerPulse = New Timer As "Pulse"
  191.     $hTimerPulse.Delay = 50
  192.     $hTimerPulse.Start
  193.     $fValue = 0
  194.     $iPulse = 0
  195.   Else
  196.     $hTimerPulse = Null
  197.  
  198.  
  199. Public Sub Pulse_Timer()
  200.  
  201.   Inc $iPulse
  202.   Me.Refresh
  203.  
  204.  
  205. Private Function Border_Read() As Boolean
  206.  
  207.   Return $bBorder
  208.  
  209.  
  210. Private Sub Border_Write(Value As Boolean)
  211.  
  212.   $bBorder = Value
  213.   Me.Refresh
  214.  
  215.  
  216.  
  217.   Return $sText
  218.  
  219.  
  220. Private Sub Text_Write(Value As String)
  221.  
  222.   $sText = Value
  223.   Me.Refresh
  224.  
  225.  
  226. '-- INSERTED ------------------------------------------
  227. Private Function TextColor_Read() As Integer
  228.  
  229.   Return $sTextColor
  230.  
  231.  
  232. Private Sub TextColor_Write(Value As Integer)
  233.  
  234.   $sTextColor = Value
  235.   Me.Refresh
  236.  
  237. '------------------------------------------------------------
  238.  
  239.  
  240.  

Regards,
Yogi
Online now: No Back to the top
1 guest and 0 members have just viewed this.