SetGadgetColor() with BUTTON_OK or BUTTON_CANCEL style button gadgets

Started by _PJ_, September 16, 2024, 11:17:23

Previous topic - Next topic

_PJ_

Code: BASIC
Import MaxGui.Drivers

Global window:TGadget = CreateWindow("MaxGUI Buttons",40,40,400,330,Null,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS)
	Local button:TGadget = CreateButton("Button",10,10,120,30,window,BUTTON_PUSH)

The following colours the button itself
SetGadgetColor(button,255,0,0)

However, when defining the gadget as OK style
Code: BASIC
Local button:TGadget = CreateButton("Button",10,10,120,30,window,BUTTON_OK)
or CANCEL style
Code: BASIC
Local button:TGadget = CreateButton("Button",10,10,120,30,window,BUTTON_CANCEL)

SetGadgetColor(button,255,0,0)
Only seems to create a thin border around the edge.

I have experimented with setting the BG (background) parameter [ default false ] but this seems to have little effect in the case of such buttons.

Is there any way to apply colour to the buttons defined with OK or CANCEL --- Alternatively, is there a means to apply this OK or CANCEL style to BUTTON_PUSH after creation?

Midimaster

Something like this? Here all three buttons have different back colors. But the first button reacts also on RETURN key press, and the second button on ESCAPE key:

Code: BASIC
SuperStrict
Import MaxGui.Drivers

Global window:TGadget = CreateWindow("MaxGUI Buttons",40,40,400,330,Null,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS)
Local button1:TGadget =    CreateButton("OK",10,10,120,30,window,BUTTON_PUSH)
Local button2:TGadget =    CreateButton("CANCEL",140,10,120,30,window,BUTTON_PUSH)
Local button3:TGadget =    CreateButton("Normal",270,10,120,30,window,BUTTON_PUSH)


SetGadgetColor button1,255,111,111
SetGadgetColor button2,111,255,111
SetGadgetColor button3,111,111,255

SetGadgetHotKey button1, KEY_RETURN, 0
SetGadgetHotKey button2, KEY_ESCAPE, 0

Repeat
    Select WaitEvent()
        Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE
            End
        Case EVENT_GADGETACTION
            Print "EVENT_GADGETACTION~n" + ..
            "GadgetText(): ~q" + GadgetText(TGadget(EventSource())) + "~q ~t " + ..
            "ButtonState(): "+ ButtonState(TGadget(EventSource()))
    EndSelect
Forever
...on the way to China.

Baggey

@Midimaster Can the Button be replaced with a .bmp or .jpg / .png ? ::)

Kind Regards Baggey
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on 2 x HP Z24's . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Raspberry Pi Black Edition! , ZX Spectrum 48k, C64, Enterprise 128K, The SID chip. Im Misunderstood!

Midimaster

Something like that?

Code: BASIC
SuperStrict
Import MaxGui.Drivers

Global window:TGadget    = CreateWindow("MaxGUI Buttons",40,40,400,330,Null,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS)
Local Button:TGadget     = CreateButton("OK",10,10,104,56,window,BUTTON_PUSH)
Local BackGround:TPixmap = LoadPixmap("wood.png")

SetGadgetPixmap Button, BackGround, PANELPIXMAP_CENTER | GADGETPIXMAP_ICON | GADGETPIXMAP_NOTEXT

Repeat
    Select WaitEvent()
        Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE
            End
        Case EVENT_GADGETACTION
            Print "EVENT_GADGETACTION~n" + ..
            "GadgetText(): ~q" + GadgetText(TGadget(EventSource())) + "~q ~t " + ..
            "ButtonState(): "+ ButtonState(TGadget(EventSource()))
    EndSelect
Forever

You need the WOOD.PNG from the attachment to run this example

Wood.png
...on the way to China.

Baggey

I tried making my own wood.png!? But it dosen't work. I suppose it has to be a certain size in a certain format as well?

Ahh i see the attachment now.

We need some windows tutorials
Running a PC that just Aint fast enough!? i7 4Ghz Quad core 32GB ram  2x1TB SSD and NVIDIA Quadro K1200 on 2 x HP Z24's . DID Technology stop! Or have we been assimulated!

Windows10, Parrot OS, Raspberry Pi Black Edition! , ZX Spectrum 48k, C64, Enterprise 128K, The SID chip. Im Misunderstood!

_PJ_

Perfect! Thanks Midimaster

Creating buttons with just BUTTON_PUSH style, but setting the GADGET_HOTKEY for KEY_ESCAPE or KEY_RETURN works exactly as intended!