FlatButtonEx Crossplattform

Share your advanced PureBasic knowledge/code with the community.
User avatar
idle
Always Here
Always Here
Posts: 5836
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: FlatButtonEx Crossplattform

Post by idle »

yes that's working fine.
Windows 11, Manjaro, Raspberry Pi OS
Image
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: FlatButtonEx Crossplattform

Post by ts-soft »

Here the same example, but using EM_EventManager: http://www.purebasic.fr/english/viewtop ... 89#p406789

Code: Select all

EnableExplicit

UsePNGImageDecoder()

XIncludeFile "FlatButtonEx.pbi"     ; http://www.purebasic.fr/english/viewtopic.php?p=405635#p405635
XIncludeFile "EM_EventManager.pbi"  ; http://www.purebasic.fr/english/viewtopic.php?p=406789#p406789

#win_Main = 0
#Font1 = 0
#Font2 = 1

Enumeration ; Image
  #IMG_PureBasic
  #IMG_About
  #IMG_Exit
EndEnumeration

Global.FlatButtonEx btnLogo, btnAbout, btnText, btnExit

Procedure.f GradientCallback(x, y)
  ProcedureReturn Sin(x * 0.5) * Sin(y * 0.5)
EndProcedure

;{ EventHandler Procedures
Procedure Window_Close(*ev.EM_Events)
  Select MessageRequester("FlatButtonEx", "Are your sure?", #PB_MessageRequester_YesNo)
    Case #PB_MessageRequester_Yes
      End
  EndSelect
EndProcedure

Procedure Window_Resize(*ev.EM_Events)
  btnLogo\Resize(#PB_Ignore, #PB_Ignore, WindowWidth(#win_Main) - 20, WindowHeight(#win_Main) - 50)
  btnAbout\Resize(#PB_Ignore, WindowHeight(#win_Main) - 30, #PB_Ignore, #PB_Ignore)
  btnText\Resize(#PB_Ignore, WindowHeight(#win_Main) - 30, WindowWidth(#win_Main) - 200, #PB_Ignore)
  btnExit\Resize(WindowWidth(#win_Main) - 90, WindowHeight(#win_Main) - 30, #PB_Ignore, #PB_Ignore)
EndProcedure

Procedure btnLogo_Default(*ev.EM_Events)
  If *ev\EventType = #PB_EventType_LeftClick
    RunProgram("http:/www.purebasic.com")
  Else
    btnLogo\Update(*ev\EventType)
  EndIf
EndProcedure

Procedure btnAbout_Click(*ev.EM_Events)
  MessageRequester("FlatButtonEx", "Example by ts-soft")
EndProcedure

Procedure btnAbout_Default(*ev.EM_Events)
  btnAbout\Update(*ev\EventType)
EndProcedure

Procedure btnText_Click(*ev.EM_Events)
  Debug "Text only Button clicked"
EndProcedure

Procedure btnText_Default(*ev.EM_Events)
  btnText\Update(*ev\EventType)
EndProcedure

Procedure btnExit_Click(*ev.EM_Events)
  Window_Close(*ev.EM_Events)
EndProcedure

Procedure btnExit_Default(*ev.EM_Events)
  btnExit\Update(*ev\EventType)
EndProcedure
;}

; On Linux or MacOS, please change the path to another picture to work!
LoadImage(#IMG_PureBasic, #PB_Compiler_Home + "Examples/Sources/Data/PureBasicLogo.bmp")

CatchImage(#IMG_About, ?Information_png_start)
CatchImage(#IMG_Exit, ?ExitSign_png_start)

LoadFont(#Font1, "Arial", 10)
LoadFont(#Font2, "Arial", 9, #PB_Font_Bold)

OpenWindow(#win_Main, #PB_Ignore, #PB_Ignore, 340, 120, "FlatButtonEx Example", #PB_Window_SystemMenu | #PB_Window_SizeGadget)
EM_SetEventHandler(#PB_Event_CloseWindow, #EM_Special, @Window_Close())
EM_SetEventHandler(#PB_Event_SizeWindow, #EM_Special, @Window_Resize())
SmartWindowRefresh(#win_Main, #True)

btnLogo = New_FlatButtonEx(10, 10, WindowWidth(#win_Main) - 20, WindowHeight(#win_Main) - 50, #False, 0)
btnLogo\SetImage(#IMG_PureBasic)
btnLogo\SetToolTip("PureBasic Home")
btnLogo\SetCursor(#PB_Cursor_Hand)
EM_SetEventHandler(btnLogo\GetID(), #EM_Gadget, @btnLogo_Default())

btnAbout = New_FlatButtonEx(10, WindowHeight(#win_Main) - 30, 80, 25, #True, #PB_Shortcut_Return)
btnAbout\SetImage(#IMG_About)
btnAbout\SetText("About")
btnAbout\SetFont(#Font1)
EM_SetEventHandler(btnAbout\GetID(), #EM_Gadget, @btnAbout_Click(), #PB_EventType_LeftClick)
EM_SetEventHandler(btnAbout\GetID(), #EM_Gadget, @btnAbout_Default())

btnText = New_FlatButtonEx(100, WindowHeight(#win_Main) - 30, WindowWidth(#win_Main) - 200, 25, #True, #PB_Shortcut_Return)
btnText\SetFont(#Font2)
btnText\SetText("Text only Button")
btnText\SetColor(#FlatButtonEx_Color_TextColor, $D9D9D9)
btnText\SetColor(#FlatButtonEx_Color_TextHotColor, $FFFFFF)
btnText\SetGradient($8A0000, $FF0303)
btnText\SetHotGradient($B90000, $FF3B3B)
btnText\SetGradientType(#FlatButtonEx_Gradient_Custom, @GradientCallback())
EM_SetEventHandler(btnText\GetID(), #EM_Gadget, @btnText_Click(), #PB_EventType_LeftClick)
EM_SetEventHandler(btnText\GetID(), #EM_Gadget, @btnText_Default())

btnExit = New_FlatButtonEx(WindowWidth(#win_Main) - 90, WindowHeight(#win_Main) - 30, 80, 25, #True, #PB_Shortcut_Return)
btnExit\SetText("Exit")
btnExit\SetImage(#IMG_Exit)
btnExit\SetFont(#Font1)
EM_SetEventHandler(btnExit\GetID(), #EM_Gadget, @btnExit_Click(), #PB_EventType_LeftClick)
EM_SetEventHandler(btnExit\GetID(), #EM_Gadget, @btnExit_Default())

SetActiveGadget(btnAbout\GetID())

Repeat : WaitWindowEvent() : ForEver

DataSection
  Information_png_start:
    ; size : 484 bytes
    Data.q $0A1A0A0D474E5089,$524448490D000000,$1000000010000000,$FFF31F0000000608,$414449AB01000061
    Data.q $024BCF939DDA7854,$2FDB2CABBFC71051,$5D904410EB2484D7,$5D16105104450EC2,$241427F5BA5C820A
    Data.q $AE8763C13753A5D4,$4E8240FD26E952DD,$4125D514BA325D46,$9B5D5B6176B448B3,$CCC303A85929AE57
    Data.q $871E76666F3E663E,$9220D40E02040932,$914E262B9F0D2524,$4BB24005AB9D2559,$B972380195D027EA
    Data.q $5F4CD9B01DBB19F8,$A43217023CC9B711,$74CCA5CC3BF45691,$BB698B1033F3C75A,$6EDC27658AE65804
    Data.q $B386F077C4CC94BE,$DBA6563C9D261CFB,$6E6344489067AE2A,$A7411508F1E00957,$D43F30573BD81F37
    Data.q $A0C10F57E141D98C,$56BC38E8AD2037FA,$60A2014E1303C2D1,$63AB29E0075CD982,$B2CEC551EC4144FB
    Data.q $5ABBC157D7C88708,$F05921BD5555E240,$5F1E000D1D384479,$82DA34B16508D873,$1580CFE29D0101A9
    Data.q $AA7B14D8D61C316A,$E1E0CFDCD80605FE,$160B5B19934B0F25,$71D193210CFC76F4,$707B1A75C965AC7C
    Data.q $D166D2B567D07B47,$094A15AC8051F289,$3C406FF6DD0E36B6,$1ED20B5468D97FAE,$70E93ACC91600648
    Data.q $B776E3396593B5B5,$A5AF32F2E0162D5B,$C43F28D78E827A52,$DCD9C616F3FE0795,$52F6FB337678C6C6
    Data.q $9562946A1C399FB2,$872805D7951BE641,$9FCE7F2CDA300C34,$F9A81272ABBFF53B,$444E454900000000
    Data.b $AE,$42,$60,$82
  Information_png_end:

  ExitSign_png_start:
    ; size : 367 bytes
    Data.q $0A1A0A0D474E5089,$524448490D000000,$1000000010000000,$FFF31F0000000608,$4144493601000061
    Data.q $3010A06463DA7854,$00F10E874380C552,$B3B3B27EF5123E29,$84E4076CD408C2FB,$34A603205580E991
    Data.q $E18E70C73ECA6F7D,$AA9431A529E6101D,$E930C499DF7431E4,$31F07EF8BAAC2CDE,$4D76717431687168
    Data.q $88DB203DF0101B05,$5C026DDF392C08C1,$92FA8D143F2EFDA1,$5DEC213B74930C9A,$B00C4037381B0C76
    Data.q $9609C0C9CD976EFB,$A4A04170C58A5548,$CC34C15BE7FAC337,$0F38870C3A5DD900,$2290018496400C21
    Data.q $E3E06C0576EC7810,$C359AAD01B714FEF,$44EBD8AC05BD7D50,$204D60558B36C318,$7C193B9796C0C0D7
    Data.q $CCE817E80D31DDC4,$11CDFFB4D20C9986,$7689B3B0456E1506,$08D9388AE4104801,$94095E283A6DD906
    Data.q $AB1A60ADE3C18605,$031DE7F77858A001,$641857816DA04FC3,$1BC54837001AA3D7,$76965EFB2CCC2C6B
    Data.q $8403101D3816E18B,$B280E961080D5080,$DA640BCA29220894,$4DC3AE587F00070C,$490000000017426F
    Data.b $45,$4E,$44,$AE,$42,$60,$82
  ExitSign_png_end:
EndDataSection
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply