PureBasic Forum http://forums.purebasic.com/english/ |
|
FrameGadgetCustom() http://forums.purebasic.com/english/viewtopic.php?f=12&t=69356 |
Page 1 of 1 |
Author: | Dude [ Sun Oct 08, 2017 1:17 am ] |
Post subject: | FrameGadgetCustom() |
Here's a little procedure that creates a customised FrameGadget(), by letting you change the text color and font for it. Credit: Based on code from Rashad here: viewtopic.php?p=513085#p513085 ![]() Code: Procedure FrameGadgetCustom(gad,x,y,w,h,text$,color,fontid=0)
If fontid SetGadgetFont(#PB_Default,fontid) EndIf tmp=TextGadget(#PB_Any,0,0,0,0,text$) tmpw=GadgetWidth(tmp,#PB_Gadget_RequiredSize) tmph=GadgetHeight(tmp,#PB_Gadget_RequiredSize) FreeGadget(tmp) FrameGadget(gad,x,y,w,h," ") gadnum=TextGadget(#PB_Any,x+10,y,tmpw+1,tmph,text$) SetGadgetColor(gadnum,#PB_Gadget_FrontColor,color) If fontid SetGadgetFont(#PB_Default,#PB_Default) EndIf ProcedureReturn gadnum EndProcedure OpenWindow(0,200,200,420,150,"Window",#PB_Window_SystemMenu) PanelGadget(0,10,10,210,130) AddGadgetItem(0,-1,"Panel") FrameGadgetCustom(1,10,10,180,85,"Blue",#Blue,FontID(LoadFont(#PB_Any,"Broadway",20))) CloseGadgetList() FrameGadgetCustom(2,230,23,180,118,"Red",#Red) Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow |
Author: | Kwai chang caine [ Wed Oct 11, 2017 10:23 am ] |
Post subject: | Re: FrameGadgetCustom() |
Very nice and useful Works perfectly, thanks to you and RASHAD ![]() |
Author: | Thorsten1867 [ Wed Oct 11, 2017 2:05 pm ] |
Post subject: | [Module] CustomFrameModule.pbi |
Code: ;/ === CustomFrameModule [PB 5.6x] === ;/ Custom frame gadget ;/ October 2017 by Dude DeclareModule CustomFrame Declare.i Gadget(GadgetID.i, X.i, Y.i, Width.i, Height.i, Text$, FontID=#PB_Ignore) Declare SetColor(GadgetID.i, Color.i) Declare SetText(GadgetID.i, Text$) EndDeclareModule Module CustomFrame EnableExplicit Structure TextStructure ID.i X.i Y.i Font.i EndStructure Global NewMap Text.TextStructure() Procedure.i Gadget(GadgetID.i, X.i, Y.i, Width.i, Height.i, Text$, FontID=#PB_Ignore) Define.i GId, GadgetH, GadgetW If FontID <> #PB_Ignore : SetGadgetFont(#PB_Default, FontID) : EndIf GId = TextGadget(#PB_Any, 0, 0, 0, 0, Text$) If GId GadgetW = GadgetWidth(GId, #PB_Gadget_RequiredSize) GadgetH = GadgetHeight(GId, #PB_Gadget_RequiredSize) FreeGadget(GId) EndIf FrameGadget(GadgetID, X, Y, Width, Height, " ") GId = TextGadget(#PB_Any, X+10, Y, GadgetW+1, GadgetH, Text$) If GId AddMapElement(Text(), Str(GadgetID)) Text()\ID = GId Text()\X = X+10 Text()\Y = Y Text()\Font = FontID EndIf If FontID <> #PB_Ignore : SetGadgetFont(#PB_Default, #PB_Default) : EndIf ProcedureReturn GId EndProcedure Procedure SetColor(GadgetID.i, Color.i) Define GID$ = Str(GadgetID) SetGadgetColor(Text(GID$)\ID, #PB_Gadget_FrontColor, Color) EndProcedure Procedure SetText(GadgetID.i, Text$) Define GId.i, GadgetH, GadgetW, GID$ = Str(GadgetID) If Text(GID$)\Font <> #PB_Ignore : SetGadgetFont(#PB_Default, Text(GID$)\Font) : EndIf GId = TextGadget(#PB_Any, 0, 0, 0, 0, Text$) If GId GadgetW = GadgetWidth(GId, #PB_Gadget_RequiredSize) GadgetH = GadgetHeight(GId, #PB_Gadget_RequiredSize) FreeGadget(GId) EndIf GId = Text(GID$)\ID ResizeGadget(GId, Text(GID$)\X, Text(GID$)\Y, GadgetW+1, GadgetH) SetGadgetText(GId, Text$) If Text(GID$)\Font <> #PB_Ignore : SetGadgetFont(#PB_Default, #PB_Default) : EndIf EndProcedure EndModule CompilerIf #PB_Compiler_IsMainFile #Panel = 0 #Frame1 = 1 #Frame2 = 2 If OpenWindow(0,200,200,420,150,"Window",#PB_Window_SystemMenu) If PanelGadget(#Panel, 10, 10, 210, 130) AddGadgetItem(#Panel, -1, "Panel") CustomFrame::Gadget(#Frame1, 10, 10, 180, 85, "Blue", FontID(LoadFont(#PB_Any, "MV Boli", 18, 256))) CustomFrame::SetColor(#Frame1, #Blue) CloseGadgetList() EndIf CustomFrame::Gadget(#Frame2, 230, 23, 180, 118, "Red") CustomFrame::SetColor(#Frame2, #Red) MessageRequester("CustomFrameModule", "Change color and text.", #PB_MessageRequester_Ok) CustomFrame::SetText(#Frame1, "New Text") CustomFrame::SetColor(#Frame2, #Green) Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow EndIf CompilerEndIf Changed: CustomFrame::Gadget(GadgetID.i, X.i, Y.i, Width.i, Height.i, Text$, FontID=#PB_Ignore) Added: CustomFrame::SetColor(GadgetID.i, Color.i) Added: CustomFrame::SetText(GadgetID.i, Text$) |
Author: | ar-s [ Wed Apr 03, 2019 1:10 pm ] |
Post subject: | Re: FrameGadgetCustom() |
Thanks Dude. Adding BGcolor to the Dude procedure. Could be usefull with a container for exemple. Code: Procedure FrameGadgetCustom(gad,x,y,w,h,text$,color,bgcolor,fontid=0)
If fontid SetGadgetFont(#PB_Default,fontid) EndIf tmp=TextGadget(#PB_Any,0,0,0,0,text$) tmpw=GadgetWidth(tmp,#PB_Gadget_RequiredSize) tmph=GadgetHeight(tmp,#PB_Gadget_RequiredSize) FreeGadget(tmp) FrameGadget(gad,x,y,w,h," ") gadnum=TextGadget(#PB_Any,x+7,y,tmpw+1,tmph,text$) SetGadgetColor(gadnum,#PB_Gadget_FrontColor,color) SetGadgetColor(gadnum,#PB_Gadget_BackColor,bgcolor) If fontid SetGadgetFont(#PB_Default,#PB_Default) EndIf ProcedureReturn gadnum EndProcedure #BGCOL = $AAAAAA OpenWindow(0,200,200,420,150,"Window",#PB_Window_SystemMenu) SetWindowColor(0,$00aacc) ContainerGadget(2,5,5,410,140) SetGadgetColor(2,#PB_Gadget_BackColor,$AAAAAA) FrameGadgetCustom(1,10,10,180,85,"Blue",#Blue,#BGCOL,FontID(LoadFont(#PB_Any,"Broadway",20))) CloseGadgetList() Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow |
Author: | Kwai chang caine [ Thu Apr 04, 2019 10:10 am ] |
Post subject: | Re: FrameGadgetCustom() |
Thanks to all for sharing ![]() |
Page 1 of 1 | All times are UTC + 1 hour |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |