gadget color
gadget color
I am relatively new to PB programming even though being interested for several years. I finally bought a copy and am working on my first "large" program and have run into some obstacles:
I would like a simple control which allows me to change its color as well as generate a user event. Button gadgets do not allow changing color and Text gadgets do not generate a user event.
I am manually creating an array of controls on my main screen. Is there anyway to use the Forms designer without having #PB_Any conflict with my manually assigned gadget numbers?
I would like a simple control which allows me to change its color as well as generate a user event. Button gadgets do not allow changing color and Text gadgets do not generate a user event.
I am manually creating an array of controls on my main screen. Is there anyway to use the Forms designer without having #PB_Any conflict with my manually assigned gadget numbers?
Re: gadget color
Hi, I'm not using any designer.
The easiest way is to use ButtonImageGadgets for text output.
You create an image, write your text on it and insert the image into the gadget.
The easiest way is to use ButtonImageGadgets for text output.
You create an image, write your text on it and insert the image into the gadget.
Last edited by Saki on Sat Aug 29, 2020 9:05 pm, edited 1 time in total.
地球上の平和
Re: gadget color
Hi Saki,
Thanks for your prompt reply. How do I put my text into the image from within my program? The Caption attribute does not seem to work with this gadget.
Thanks for your prompt reply. How do I put my text into the image from within my program? The Caption attribute does not seem to work with this gadget.
Re: gadget color
Hi simplest so
Code: Select all
window_ID=OpenWindow(#PB_Any , 0 , 0 , 600 , 400 , "" , #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
button_ID = ButtonImageGadget(#PB_Any , 100 , 100 , 200 , 60 , 0)
image_ID = CreateImage(#PB_Any , 200 , 60 , 32 , $FF)
StartDrawing(ImageOutput(image_ID))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(10 , 10 , "Hello World")
StopDrawing()
SetGadgetAttribute(button_ID, #PB_Button_Image , ImageID(image_ID))
Repeat
Define win_event = WaitWindowEvent()
Until win_event = #PB_Event_CloseWindow
地球上の平和
Re: gadget color
Hi Saki,
Thanks again for your reply. That seems like a lot of trouble just because PB does not allow changing a button color. I will try it if no other solution is posted.
Thanks again for your reply. That seems like a lot of trouble just because PB does not allow changing a button color. I will try it if no other solution is posted.
Re: Gadget-Farbe
Hi, just look for finished custom gadgets here in the forum.
There is no simple solution with PB means.
The better the solution the more difficult it is to code.
There is no simple solution with PB means.
The better the solution the more difficult it is to code.
地球上の平和
Re: gadget color
When you get more experience with PureBasic, you'll realise that little code is nowhere near a lot of trouble. In fact, it's dead simple, quick, and easy.k3pto wrote:That seems like a lot of trouble
ButtonGadgets don't support color because their underlying Windows control doesn't support it. Even with something like Visual Basic, you need extra code to add color to a button.
But here's some code that makes it more convenient for you. It's not perfect (the buttons are not 100% like standard ones), but it's a good compromise or starting point. Not my code.
Don't forget to search the forums too for phrases like "colored button" because literally almost every question like yours has been asked and answered before, with working examples.
For example -> viewtopic.php?f=12&t=59066
Code: Select all
Procedure ButtonGadgetColor(gad,x,y,w,h,text$="",flags=0,fgcolor=#PB_Default,bgcolor=#PB_Default,font=#PB_Default)
If bgcolor=#PB_Default : bgcolor=GetSysColor_(#COLOR_BTNFACE) : EndIf
If fgcolor=#PB_Default : fgcolor=GetSysColor_(#COLOR_BTNFACE) : EndIf
If font=#PB_Default : font=GetStockObject_(#DEFAULT_GUI_FONT) : EndIf
text=CreateImage(#PB_Any,w,h)
If StartDrawing(ImageOutput(text))
DrawingFont(font) : Box(0,0,w,h,bgcolor)
DrawText(w/2-TextWidth(text$)/2,h/2-TextHeight(text$)/2,text$,fgcolor,bgcolor)
StopDrawing() : ok=ButtonImageGadget(gad,x,y,w,h,ImageID(text),flags)
EndIf
ProcedureReturn ok
EndProcedure
OpenWindow(0,100,100,340,100,"Colored Buttons",#PB_Window_SystemMenu)
ButtonGadgetColor(1,10,10,150,30,"toggle",#PB_Button_Toggle,#White,#Red)
ButtonGadgetColor(2,10,50,150,30,"courier",0,#Blue,#Yellow,LoadFont(0,"courier",12))
ButtonGadget(#PB_Any,170,10,150,30,"normal")
ButtonGadgetColor(#PB_Any,170,50,150,30,"normal + red",0,#Red)
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
Re: gadget color
Hi BarryG,
Thanks for the response. I did try to search but obviously did not use the correct terms. I will see what I can do with the sample code you sent.
Thanks for the response. I did try to search but obviously did not use the correct terms. I will see what I can do with the sample code you sent.
Re: gadget color
All good. Also check out the example link I gave that leads to TI-994A's code (scroll to the bottom to see a screenshot).
Re: gadget color
For owner controls show PB CanvasGadget ...
Examples of flat gadget as OOP style show Link viewtopic.php?f=12&t=74267
Examples of flat gadget as OOP style show Link viewtopic.php?f=12&t=74267
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Gadget-Farbe
Well, of course it is not so easy to find something suitable, these things are often well hidden.
viewtopic.php?f=12&t=66927
The first address for such things is the GFX_Wizzard_BF, which you can not deny.
Several authors, as well as myself, develop new functions and add extensions for the GFX_Wizzard_BF.
The next days there will be a whole bag of new incredible text functions for and without gadgets.
Custom gadgets are often created canvas based.
But if you want the perfect look and feel of the OS, there is no way around ButtonImageGadgets.
They are also much easier to use.
For your problem just look for StretchText Gadget, or any other
And it is really not that easy.
Really good codes become very large and complicated to code very quickly
The problems start with the automatic fitting of the text, text length and text size for multiline texts and continue with the fitting and alignment of the text.
Yes and you don't need to load any fonts at all, if you want to use a special one, just enter its name.
The same with the Font Flags, you can specify them, but you don't have to.
The text size is adjusted automatically, also the alignment and padding.
You can change everything by hand, but primarily you don't have to do anything at all, it always fits.
These are just the small differences.
Best Regards Saki
viewtopic.php?f=12&t=66927
The first address for such things is the GFX_Wizzard_BF, which you can not deny.
Several authors, as well as myself, develop new functions and add extensions for the GFX_Wizzard_BF.
The next days there will be a whole bag of new incredible text functions for and without gadgets.
Custom gadgets are often created canvas based.
But if you want the perfect look and feel of the OS, there is no way around ButtonImageGadgets.
They are also much easier to use.
For your problem just look for StretchText Gadget, or any other
And it is really not that easy.
Really good codes become very large and complicated to code very quickly
The problems start with the automatic fitting of the text, text length and text size for multiline texts and continue with the fitting and alignment of the text.
Yes and you don't need to load any fonts at all, if you want to use a special one, just enter its name.
The same with the Font Flags, you can specify them, but you don't have to.
The text size is adjusted automatically, also the alignment and padding.
You can change everything by hand, but primarily you don't have to do anything at all, it always fits.
These are just the small differences.
Best Regards Saki
Last edited by Saki on Sun Aug 30, 2020 1:56 pm, edited 5 times in total.
地球上の平和
Re: gadget color
As far as I know it's not a PB matter, as most Gadgets are part of the operating system.k3pto wrote:Hi Saki,
Thanks again for your reply. That seems like a lot of trouble just because PB does not allow changing a button color. I will try it if no other solution is posted.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Re: Gadget-Farbe
Hi Joris,
So myself as a software developer the perfect implementation has pushed me to my limits.
But it is possible to achieve fascinating results, which go far beyond the OS.
Unfortunately, I also cannot invert endless time into this free thing, because also unfortunately for me time is money.
Best Regards
Saki
So myself as a software developer the perfect implementation has pushed me to my limits.
But it is possible to achieve fascinating results, which go far beyond the OS.
Unfortunately, I also cannot invert endless time into this free thing, because also unfortunately for me time is money.
Best Regards
Saki
地球上の平和
Re: gadget color
I had the same question... in the end, do not use #PB_Any in Form Designer, and somewhere (I have a globals.pbi file) create your own enumerate:k3pto wrote:Is there anyway to use the Forms designer without having #PB_Any conflict with my manually assigned gadget numbers?
Code: Select all
Enumeration FormGadget
#MyButton1
#MoreButtons
EndEnumeration
Re: Gadget-Farbe
I have not been dealing with PureBasic for long.
The designers are too limited for me.
It is important that the used designer supports dynamic resizing and has as few restrictions as possible.
And the trouble-free support of custom gadgets should work.
If this is not the case massive problems can occur.
#PB_Any is in itself what you expect.
After creating a Gadget you get back its unique ID, that's how it should be.
If you switch from one screen to another, with different resolutions,
the easiest thing to do is to make the GUI scalable in size without destroying the content or making it unreadably small.
It is basically easy to create a framework for a dynamic GUI yourself.
But it is also necessary that the gadgets, images and text can be adjusted proportionally to any desktop resolution.
The designers are too limited for me.
It is important that the used designer supports dynamic resizing and has as few restrictions as possible.
And the trouble-free support of custom gadgets should work.
If this is not the case massive problems can occur.
#PB_Any is in itself what you expect.
After creating a Gadget you get back its unique ID, that's how it should be.
If you switch from one screen to another, with different resolutions,
the easiest thing to do is to make the GUI scalable in size without destroying the content or making it unreadably small.
It is basically easy to create a framework for a dynamic GUI yourself.
But it is also necessary that the gadgets, images and text can be adjusted proportionally to any desktop resolution.
地球上の平和