October 26, 2020, 01:05:28 AM

Author Topic: SetGadgetColor/SetGadgetTextColor on window statusbar labels not working  (Read 2061 times)

Offline chalky

  • Jr. Member
  • **
  • Posts: 62
I have created a window with a status bar and used SetParent to attach labels to it so that I can have some text panels. These work fine and can be updated via SetGadgetText without problems. However, once parented, SetGadgetColor/SetGadgetTextColor settings are ignored and the labels are displayed using the default windows theme colours.

I was hoping to change the colour of text in the panels to indicate the status of special keys (i.e. INS, CAPS, NUMLOCK etc.) whereby they are grey when off, and black when on - does anyone know of a trick which will make SetGadgetColor/SetGadgetTextColor work on labels parented to a window's statusbar?

Offline Henri

  • Sr. Member
  • ****
  • Posts: 263
Hi,

can you post a small example showing how you set things up ? This is somewhat custom functionality in MaxGUI.

Edit: There doesn't seem to be any hardcoded limitations that prohibit colouring:

-Henri
- Got 01100011 problems, but the bit ain't 00000001

Offline Derron

  • Hero Member
  • *****
  • Posts: 3234
wxStatusBar - vs - MaxGUI statusbar.


I assume this is not the same.


bye
Ron

Offline chalky

  • Jr. Member
  • **
  • Posts: 62
This is a cut-down example of what I'm doing:

Code: [Select]
SuperStrict

Import maxgui.drivers

Extern "win32"
Function SetParent:Int(hWndChild:Int,hWndNewParent:Int)
End Extern

SetGraphicsDriver D3D7Max2DDriver()

Local hLabel:Int
Local hStatus:Int

Local wndMain:TGadget=CreateWindow("My App",200,100,500,400,,WINDOW_TITLEBAR|WINDOW_RESIZABLE|WINDOW_STATUS|WINDOW_CLIENTCOORDS)
Local lblPOS:TGadget=CreateLabel("Statusbar",1,3,92,18,wndMain,LABEL_SUNKENFRAME)
Local lblCAP:TGadget=CreateLabel("CAPS",ClientWidth(wndMain)-130,3,40,18,wndMain,LABEL_SUNKENFRAME|LABEL_CENTER)
Local lblNUM:TGadget=CreateLabel("NUM",ClientWidth(wndMain)-90,3,30,18,wndMain,LABEL_SUNKENFRAME|LABEL_CENTER)
Local lblSCR:TGadget=CreateLabel("SCRL",ClientWidth(wndMain)-60,3,40,18,wndMain,LABEL_SUNKENFRAME|LABEL_CENTER)

' build status bar
SetGadgetLayout(lblPOS,EDGE_ALIGNED,EDGE_CENTERED,EDGE_ALIGNED,EDGE_CENTERED)
SetGadgetLayout(lblCAP,EDGE_CENTERED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_CENTERED)
SetGadgetLayout(lblNUM,EDGE_CENTERED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_CENTERED)
SetGadgetLayout(lblSCR,EDGE_CENTERED,EDGE_ALIGNED,EDGE_ALIGNED,EDGE_CENTERED)

SetGadgetTextColor(lblCAP,255,0,0)
SetGadgetTextColor(lblNUM,0,255,0)
SetGadgetTextColor(lblSCR,0,0,255)

'Rem -> The enclosed code stops SetGadgetTextColor working...
hStatus=TWindowsWindow(wndMain)._status
hLabel=QueryGadget(lblPOS,QUERY_HWND)
SetParent(hLabel,hStatus)
hLabel=QueryGadget(lblCAP,QUERY_HWND)
SetParent(hLabel,hStatus)
hLabel=QueryGadget(lblNUM,QUERY_HWND)
SetParent(hLabel,hStatus)
hLabel=QueryGadget(lblSCR,QUERY_HWND)
SetParent(hLabel,hStatus)
'EndRem

Repeat
WaitEvent()
Select EventID()
Case EVENT_WINDOWCLOSE
Exit
End Select
Forever
End

You will see that if you don't parent the statusbar to the labels, colouring works fine. Actually - I have just found a thread from 2010 in the old forum where I asked the same question, and it was stated that the functionality I'm looking for is not supported in MaxGUI - although apparently it is in wxMax. Unfortunately I have never been able to get the wxMax module to build on my system, so it looks like I will have to make my own statusbar using a panel.

Offline Henri

  • Sr. Member
  • ****
  • Posts: 263
Both wxMax and MaxGUI use similar underlaying API provided by platform, so usually if it's possible in wx, then it's possible in Maxgui.

I'm guessing that the problem is related to paint event, and labels are not updated correctly when parented to status bar. My idea is to parent labels to panels and parent those panels to status bar.

Like so:
Code: BlitzMax
  1. SuperStrict
  2.  
  3. Import MaxGui.Drivers
  4.  
  5. AppTitle = "MaxGUI Statusbar Example"
  6.  
  7. Extern "win32"
  8.   Function SetParent(Child:Int,Parent:Int)="SetParent@8"
  9. End Extern
  10.  
  11. Global FLAGS:Int
  12.  
  13. ' Comment/uncomment any of the following lines to experiment with the different styles.
  14.  
  15. FLAGS:| WINDOW_TITLEBAR
  16. FLAGS:| WINDOW_RESIZABLE
  17. FLAGS:| WINDOW_MENU
  18. FLAGS:| WINDOW_STATUS
  19. FLAGS:| WINDOW_CLIENTCOORDS
  20. 'FLAGS:| WINDOW_HIDDEN
  21. FLAGS:| WINDOW_ACCEPTFILES
  22. 'FLAGS:| WINDOW_TOOL
  23. 'FLAGS:| WINDOW_CENTER
  24.  
  25. Local window:TGadget = CreateWindow( AppTitle, 100, 100, 320, 240, Null, FLAGS )
  26. Local statusPanel:TGadget = CreatePanel(1, 3, 100, 19, window)
  27. Local statusLabel:TGadget = CreateLabel("My text", 0, 0, 80, 18, statusPanel)
  28.         SetGadgetColor(statusPanel, 100, 255, 255)
  29.         SetGadgetTextColor(statusLabel, 255, 100, 255)
  30.         SetGadgetLayout(statusPanel, EDGE_ALIGNED, EDGE_CENTERED, EDGE_ALIGNED, EDGE_CENTERED)
  31.  
  32. Local statusPanel2:TGadget = CreatePanel(101, 3, 100, 19, window)
  33. Local statusLabel2:TGadget = CreateLabel("Another", 0, 0, 80, 18, statusPanel2, LABEL_CENTER)
  34.         SetGadgetColor(statusPanel2, 255, 100, 255)
  35.         SetGadgetTextColor(statusLabel2, 100, 255, 255)
  36.         SetGadgetLayout(statusPanel2, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_CENTERED)
  37.         SetGadgetLayout(statusLabel2, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_CENTERED)
  38.        
  39. If (FLAGS & WINDOW_STATUS) Then
  40.         SetStatusText( window, "~t~tRight aligned  " )
  41. EndIf
  42.  
  43. SetStatusGadget(statusPanel, window)
  44. SetStatusGadget(statusPanel2, window)
  45.  
  46. Repeat
  47.         WaitEvent()
  48.        
  49.         Select EventID()
  50.                 Case EVENT_APPTERMINATE, EVENT_WINDOWCLOSE
  51.                         End
  52.         End Select
  53. Forever
  54.  
  55. Function SetStatusGadget(gadget:TGadget, parent:Tgadget)  
  56.   If Not parent Or Not gadget Then Return
  57.  
  58.   Local wg:TWindowsWindow = TWindowsWindow( TWindowsGUIDriver.GadgetFromHwnd( QueryGadget(parent, QUERY_HWND) ))
  59.   If wg Then SetParent( QueryGadget(gadget, QUERY_HWND), wg._status)
  60. End Function

-Henri
- Got 01100011 problems, but the bit ain't 00000001

Offline chalky

  • Jr. Member
  • **
  • Posts: 62
Wow - that's totally brilliant - thank you!



:D

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal