It is currently Fri Dec 06, 2019 11:01 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: FrameGadgetCustom()
PostPosted: Sun Oct 08, 2017 1:17 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1904
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

Image

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


Top
 Profile  
Reply with quote  
 Post subject: Re: FrameGadgetCustom()
PostPosted: Wed Oct 11, 2017 10:23 am 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4542
Location: Lyon - France
Very nice and useful
Works perfectly, thanks to you and RASHAD 8)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: [Module] CustomFrameModule.pbi
PostPosted: Wed Oct 11, 2017 2:05 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 24, 2005 4:02 pm
Posts: 1022
Location: Germany
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$)

_________________
Sorry for my English. My language is German.
(Translated with http://www.DeepL.com/Translator)

[url=[url=https://my.pcloud.com/publink/show?code=kZdBKYkZqACcD4wGG0B6NmwH88oyJQ56HXg7]Download for modules[/url]]Download of PureBasic - Modules[/url]

[Windows 10 x64] [PB V5.7x]


Top
 Profile  
Reply with quote  
 Post subject: Re: FrameGadgetCustom()
PostPosted: Wed Apr 03, 2019 1:10 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Oct 06, 2007 11:20 pm
Posts: 269
Location: France
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

_________________
~Ar-S~

ResizerGold : The easiest way to resize your pictures and more
My webSite (french) : LDVMULTIMEDIA
PB - 5.4x LTS / 5.6x - W10 x64 - GTX1080 - i5 6600k
Repeat : try : until done = 1


Top
 Profile  
Reply with quote  
 Post subject: Re: FrameGadgetCustom()
PostPosted: Thu Apr 04, 2019 10:10 am 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4542
Location: Lyon - France
Thanks to all for sharing 8)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye