SetGadgetColor/SetGadgetTextColor on window statusbar labels not working

Started by chalky, July 16, 2018, 21:54:34

Previous topic - Next topic

chalky

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?

Henri

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

Derron

wxStatusBar - vs - MaxGUI statusbar.


I assume this is not the same.


bye
Ron

chalky

This is a cut-down example of what I'm doing:

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.

Henri

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) Select
SuperStrict

Import MaxGui.Drivers

AppTitle = "MaxGUI Statusbar Example"

Extern "win32"
  Function SetParent(Child:Int,Parent:Int)="SetParent@8"
End Extern

Global FLAGS:Int

' Comment/uncomment any of the following lines to experiment with the different styles.

FLAGS:| WINDOW_TITLEBAR
FLAGS:| WINDOW_RESIZABLE
FLAGS:| WINDOW_MENU
FLAGS:| WINDOW_STATUS
FLAGS:| WINDOW_CLIENTCOORDS
'FLAGS:| WINDOW_HIDDEN
FLAGS:| WINDOW_ACCEPTFILES
'FLAGS:| WINDOW_TOOL
'FLAGS:| WINDOW_CENTER

Local window:TGadget = CreateWindow( AppTitle, 100, 100, 320, 240, Null, FLAGS )
Local statusPanel:TGadget = CreatePanel(1, 3, 100, 19, window)
Local statusLabel:TGadget = CreateLabel("My text", 0, 0, 80, 18, statusPanel)
SetGadgetColor(statusPanel, 100, 255, 255)
SetGadgetTextColor(statusLabel, 255, 100, 255)
SetGadgetLayout(statusPanel, EDGE_ALIGNED, EDGE_CENTERED, EDGE_ALIGNED, EDGE_CENTERED)

Local statusPanel2:TGadget = CreatePanel(101, 3, 100, 19, window)
Local statusLabel2:TGadget = CreateLabel("Another", 0, 0, 80, 18, statusPanel2, LABEL_CENTER)
SetGadgetColor(statusPanel2, 255, 100, 255)
SetGadgetTextColor(statusLabel2, 100, 255, 255)
SetGadgetLayout(statusPanel2, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_CENTERED)
SetGadgetLayout(statusLabel2, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_ALIGNED, EDGE_CENTERED)

If (FLAGS & WINDOW_STATUS) Then
SetStatusText( window, "~t~tRight aligned  " )
EndIf

SetStatusGadget(statusPanel, window)
SetStatusGadget(statusPanel2, window)

Repeat
WaitEvent()

Select EventID()
Case EVENT_APPTERMINATE, EVENT_WINDOWCLOSE
End
End Select
Forever

Function SetStatusGadget(gadget:TGadget, parent:Tgadget) 
  If Not parent Or Not gadget Then Return

  Local wg:TWindowsWindow = TWindowsWindow( TWindowsGUIDriver.GadgetFromHwnd( QueryGadget(parent, QUERY_HWND) ))
  If wg Then SetParent( QueryGadget(gadget, QUERY_HWND), wg._status)
End Function


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

chalky

Wow - that's totally brilliant - thank you!



:D