MaxGUI - Changing Gadget Color and Alpha?
BlitzMax Forums/BlitzMax Programming/MaxGUI - Changing Gadget Color and Alpha?
| ||
| Using the 1.12 BlitzMax demo (trying the GUI before buying as Mark suggested), I can't seem to get SetGadgetColor, SetGadgetTextColor, or SetGadgetAlpha to do anything (with one exception under OS X). I know that in Windows the default is to use the system's style/color scheme, but is there no way to override that with these commands (like in Visual Basic, where system colors can be replaced with custom ones)? The example below (assembled from those in the Help) doesn't change any gadget's color or alpha under Windows XP Pro SP 2. In Mac OS X 10.3.9, only the ListBox colors change, to blue text on a red background (which is what they should be). IMHO, the alpha stuff isn't that important, but it'd be very useful to be able to change colors. Am I overlooking something, or is something wrong? Strict
Local window:TGadget
Local button:TGadget[5]
window=CreateWindow("MaxGui Buttons",40,40,180,500,0,WINDOW_TITLEBAR)
button[0]=CreateButton("Push Button",10,10,140,24,window,BUTTON_PUSH)
button[1]=CreateButton("Checkbox Button",10,34,140,24,window,BUTTON_CHECKBOX)
button[2]=CreateButton("Radio Button",10,58,140,24,window,BUTTON_RADIO)
button[3]=CreateButton("OK",10,82,70,24,window,BUTTON_OK)
button[4]=CreateButton("Cancel",84,82,70,24,window,BUTTON_CANCEL)
For Local i = 0 To 4
SetGadgetColor button[i],255,0,0,True
SetGadgetColor button[i],0,255,0,False
SetGadgetTextColor button[i],0,0,255
SetGadgetAlpha button[i], 0.33
Next
Local canvas:TGadget=CreateCanvas(10,120,133,100,window)
SetGadgetColor canvas,255,0,0,True
SetGadgetColor canvas,0,255,0,False
SetGadgetTextColor canvas,0,0,255
SetGadgetAlpha canvas, 0.33
Local combobox:TGadget=CreateComboBox(10,240,120,22,window)
AddGadgetItem combobox,"Short"
AddGadgetItem combobox,"Medium"
AddGadgetItem combobox,"Fat",True
AddGadgetItem combobox,"Humungous"
SetGadgetColor combobox,255,0,0,True
SetGadgetColor combobox,0,255,0,False
SetGadgetTextColor combobox,0,0,255
SetGadgetAlpha combobox, 0.33
Local label:TGadget=CreateLabel("A plain label",10,270,280,52,window)
SetGadgetColor label,255,0,0,True
SetGadgetColor label,0,255,0,False
SetGadgetTextColor label,0,0,255
SetGadgetAlpha label, 0.33
Const ETIP$="Greate for lovers of rain, mushy peas and stomping beats.~r~nNew line..."
Local listbox:TGadget=CreateListBox(4,300,100,50,window)
AddGadgetItem listbox,"German"
AddGadgetItem listbox,"England",False,-1,ETIP
AddGadgetItem listbox,"French",False,-1,"tip - goes here","mystringobject"
SetGadgetColor listbox,255,0,0,True
SetGadgetColor listbox,0,255,0,False
SetGadgetTextColor listbox,0,0,255
SetGadgetAlpha listbox, 0.33
Local slider:TGadget[3]
' standard vertical and horizontal scroll bars
slider[0]=CreateSlider(10,360,16,100,window,SLIDER_VERTICAL)
slider[1]=CreateSlider(30,360,100,16,window,SLIDER_HORIZONTAL)
' a horizontal trackbar
slider[2]=CreateSlider(30,380,100,24,window,SLIDER_HORIZONTAL|SLIDER_TRACKBAR)
For Local i = 0 To 2
SetGadgetColor slider[i],255,0,0,True
SetGadgetColor slider[i],0,255,0,False
SetGadgetTextColor slider[i],0,0,255
SetGadgetAlpha slider[i], 0.33
Next
' a row of vertical trackbars
Local trackbar:TGadget[5]
For Local i=0 To 4
trackbar[i]=CreateSlider(30+i*20,400,16,60,window,SLIDER_VERTICAL|SLIDER_TRACKBAR)
SetGadgetColor trackbar[i],255,0,0,True
SetGadgetColor trackbar[i],0,255,0,False
SetGadgetTextColor trackbar[i],0,0,255
SetGadgetAlpha trackbar[i], 0.33
Next
' a single stepper
Local stepper:TGadget
stepper=CreateSlider(10,570,24,24,window,SLIDER_STEPPER)
SetGadgetColor stepper,255,0,0,True
SetGadgetColor stepper,0,255,0,False
SetGadgetTextColor stepper,0,0,255
SetGadgetAlpha stepper, 0.33
SetSliderValue stepper,4
Print SliderValue(stepper)
' create an update timer
CreateTimer 60
While WaitEvent()
Select EventID()
Case EVENT_TIMERTICK
RedrawGadget canvas
Case EVENT_GADGETPAINT
Local g=CanvasGraphics(canvas)
SetGraphics g
SetOrigin 67,50
SetLineWidth 5
Cls
Local t=MilliSecs()
DrawLine 0,0,120*Cos(t),60*Sin(t)
DrawLine 0,0,80*Cos(t/60),40*Sin(t/60)
Flip
Case EVENT_WINDOWCLOSE
FreeGadget canvas
End
Case EVENT_APPTERMINATE
End
End Select
Wend
While True
WaitEvent
Select EventID()
Case EVENT_WINDOWCLOSE
End
Case EVENT_TIMERTICK
RedrawGadget canvas
Case EVENT_GADGETPAINT
Local g=CanvasGraphics(canvas)
SetGraphics g
SetOrigin 160,120
SetLineWidth 5
Cls
Local t=MilliSecs()
DrawLine 0,0,120*Cos(t),120*Sin(t)
DrawLine 0,0,80*Cos(t/60),80*Sin(t/60)
Flip
Case EVENT_GADGETACTION
Print "EVENT_GADGETACTION"
End Select
Wend
|
| ||
I can change the textarea colours no problem, the main window doesn't seem to get affected by SetGadgetColor and if you try it on a menu, it causes an unhandled exception.
Strict
'CONSTS
Const MENU_NEW=101
Const MENU_OPEN=102
Const MENU_SAVE=103
Const MENU_CLOSE=104
Const MENU_EXIT=105
Const MENU_CUT=106
Const MENU_COPY=107
Const MENU_PASTE=108
Const MENU_ABOUT=109
'SETUP
Global mainWindow:TGadget = CreateWindow("Edit Pad",30,20,500,400,Null, WINDOW_TITLEBAR|WINDOW_RESIZABLE|WINDOW_MENU|WINDOW_STATUS|WINDOW_ACCEPTFILES)
Global filemenu:TGadget=CreateMenu("&File",0,WindowMenu(mainWindow))
CreateMenu"&New",MENU_NEW,filemenu,KEY_N,MODIFIER_COMMAND
CreateMenu"&Open",MENU_OPEN,filemenu,KEY_O,MODIFIER_COMMAND
CreateMenu"&Close",MENU_CLOSE,filemenu,KEY_W,MODIFIER_COMMAND
CreateMenu"",0,filemenu
CreateMenu"&Save",MENU_SAVE,filemenu,KEY_S,MODIFIER_COMMAND
CreateMenu"",0,filemenu
CreateMenu"E&xit",MENU_EXIT,filemenu,KEY_F4,MODIFIER_COMMAND
Global editmenu:TGadget=CreateMenu("&Edit",0,WindowMenu(mainWindow))
CreateMenu "Cu&t",MENU_CUT,editmenu,KEY_X,MODIFIER_COMMAND
CreateMenu "&Copy",MENU_COPY,editmenu,KEY_C,MODIFIER_COMMAND
CreateMenu "&Paste",MENU_PASTE,editmenu,KEY_V,MODIFIER_COMMAND
Global helpmenu:TGadget=CreateMenu("&Help",0,WindowMenu(mainWindow))
CreateMenu "&About",MENU_ABOUT,helpmenu
Global font_Courier:TGUIFont = LoadGuiFont("Courier New", 12)
Global textArea : TGadget = CreateTextArea(0, 0, ClientWidth(mainWindow),ClientHeight(mainWindow), mainWindow)
SetGadgetFont(textArea, font_Courier)
SetGadgetColor(textArea,155,0,0)
SetGadgetColor(textArea,255,255,255,False)
'setting menu colour causes an exception
'SetGadgetColor(fileMenu, 155,0,0)
'SetGadgetColor(fileMenu, 255,255,255, False)
UpdateWindowMenu mainWindow
'MAIN
MainLoop()
Function MainLoop()
While True
WaitEvent
Select EventID()
Case EVENT_WINDOWCLOSE
End
Case EVENT_MENUACTION
Select EventData()
Case MENU_EXIT
If Proceed("Are you sure you want to quit?") = 1 Then End
Case MENU_SAVE
SaveFile()
Case MENU_ABOUT
Notify "Simple notepad type thing in BMax~n (C) me"
End Select
Case EVENT_APPTERMINATE
If Proceed("Are you sure you want to quit?")=1 Then End
Case EVENT_GADGETACTION
?debug
'Print "EVENT_GADGETACTION"
?
Rem
Select EventSource()
End Select
EndRem
Case EVENT_WINDOWSIZE
HandleResize()
Case EVENT_WINDOWACCEPT
End Select
Wend
End Function
Function HandleResize()
SetGadgetShape(textarea, 0,0, ClientWidth(mainWindow),ClientHeight(mainWindow))
Rem
textarea.Width = ClientWidth(mainWindow)
textarea.Height = ClientHeight(mainWindow)
EndRem
End Function
Function SaveFile()
Local FileName:String
FileName = RequestFile("Save File...", "Text File:txt", True)
End Function
|
| ||
| Perturbatio, why dont you use SetGadgetLayout( textArea, 1, 1, 1, 1 ) instead of the HandleResize() function ? |
| ||
| Because I had no idea about it whatsoever, I just jumped in and decided to create a Notepad clone to see how easy the GUI was (I did this with the demo actually). But thanks for that, I was wondering how it was done :) |
| ||
| I can change the textarea colours no problem Yes. And FormatTextAreaText allows even more control if needed, so that ranges of text can be made different colors (like in the IDE), bold, and/or italic. Should be great for text displays/chat boxes/etc. the main window doesn't seem to get affected by SetGadgetColor and if you try it on a menu, it causes an unhandled exception. I haven't tried it on the window itself or on menus - thanks. But it would be handy to be able to override the default color scheme for gadgets (panels can substitute for pushbuttons, but other gadgets aren't as easily replaced). Skidracer's 07-01 worklog made it look like color control would be simple enough: The gadgestyle object is the current label, backgroundcolor, forgroundcolor, font combo but instead of a bunch of fixed size gadgets being created i'm now using the friendlier button view extensions: Type TGadgetStyle Extends TGroupView Field label:TLabel Field fg:TColorButton Field bg:TColorButton Field font:TFontButton Method Apply(gadget:TGadget) SetGadgetFont gadget,font.font SetGadgetColor gadget,bg.red,bg.green,bg.blue,True SetGadgetColor gadget,fg.red,fg.green,fg.blue,False End Method Since the ListBox does it on MaxOS, maybe it is possible, but I'm just not seeing how to do it? Or, since it only works with ListBox and only on MacOS, maybe something is weird somewhere? ----- Nov. 21, 2005 update: workaround using more-configurable panels as button replacements is now at http://blitzbasic.com/codearcs/codearcs.php?code=1539 |
| ||
| Bump, 4 months old but can't use setgadgetcolor and setgadgetalpha don't seem to do anything. |