StatusBar: #PB_Event_LeftClick

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

StatusBar: #PB_Event_LeftClick

Post by Marc56us »

I use the gadget StatusBar very much because it is simple to use and it is a basic element of Windows.
(I always think end user and especially for tools programs)

Would it be possible to add #PB_Event_LeftClick (and others) to StatusBar fields ?
Having Tooltips for fields would be good too.

Many programs (ie: editors, spreadsheets, word processing) use the click on the status bar fields for example to change the state SHIFT or NUMLOCK or the type of encoding.
I do not know if it's a simple or complicated feature to implement ?

Thanks
:wink:
Mesa
Enthusiast
Enthusiast
Posts: 349
Joined: Fri Feb 24, 2012 10:19 am

Re: StatusBar: #PB_Event_LeftClick

Post by Mesa »

Marc56us
Addict
Addict
Posts: 1479
Joined: Sat Feb 08, 2014 3:26 pm

Re: StatusBar: #PB_Event_LeftClick

Post by Marc56us »

Thanks Mesa

I suggested a native function.
I do not know how many people this may interest ?

(Just a suggestion, a simple idea, not a request)

:wink:
Wolf
Enthusiast
Enthusiast
Posts: 229
Joined: Sat Apr 03, 2004 12:00 pm
Location: S.T

Re: StatusBar: #PB_Event_LeftClick

Post by Wolf »

Marc56us wrote: I suggested a native function.
+1
destiny
User
User
Posts: 29
Joined: Wed Jul 15, 2015 12:58 pm
Location: CCCP

Re: StatusBar: #PB_Event_LeftClick

Post by destiny »

Marc56us wrote:I suggested a native function.
+1
User avatar
skywalk
Addict
Addict
Posts: 3994
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: StatusBar: #PB_Event_LeftClick

Post by skywalk »

I subclass the StatusBar on Windows, but it is not elegant.
A lighter, cross-platform approach is a bound container gadget that houses any gadget you require.
I made the canvasgadget width = the entire containergadget width, which should be modified to its actual width.

Code: Select all

; ts-soft, https://www.purebasic.fr/english/viewtopic.php?p=343795#p343795
#aWhite       = $FFFFFFFF   ; RGBA(255, 255, 255, 255)
#aBlack       = $FF000000   ; RGBA(0, 0, 0, 255)
#YellowLight  = $C0FFFF     ; RGB(255, 255, 192)
#GrayLight    = $E4E4E4     ; RGB(228, 228, 228)
#aRedLight    = $FF513CED   ; RGBA(237, 60, 81, 255)
#aGreenLight  = $FFC0FFC0   ; RGBA(192, 255, 192, 255)
Global.i fntC = FontID(LoadFont(#PB_Any, "Consolas", 14, #PB_Font_HighQuality))
Global.i evWW, evG, fntC
Macro waf_CLR_Fill(CLR=#aWhite)
  ; Default = RGBA(255, 255, 255, 255), erases all content.
  VectorSourceColor(CLR)    ; Set BG color and now the default color until changed.
  FillVectorOutput()        ; Apply BG color.
EndMacro
Procedure gad_ProgressBarTextV(gN.i, show_pc.i, txt$=#Empty$, pbHt_px.i=20, BGColor.i=#aGreenLight)
  ; Draw progress bar text to canvasgadget.
  ; '_px' -> units = pixels
  ; '_pc' -> units = %
  ; pbHt_px, pbWd_px -> progressbar Ht & Wd in pixels.
  Protected.i pbX_px, pbWd_px, tW, tH, Font
  Protected.s s$ =  "... " + Str(show_pc) + "% " + txt$ + " ..."
  show_pc = Abs(show_pc)
  If show_pc >= 100
    show_pc = 100
    s$ =  "... Done ..."
  EndIf
  StartVectorDrawing(CanvasVectorOutput(gN))
  pbX_px = GadgetX(gN, #PB_Gadget_ActualSize)
  pbWd_px = GadgetWidth(gN, #PB_Gadget_ActualSize)
  waf_CLR_Fill()
  VectorFont(fntC, pbHt_px-8)
  tW = VectorTextWidth(s$)
  tH = VectorTextHeight(s$)
  If tH > pbHt_px
    pbHt_px = tH * 1.2
  EndIf
  pbWd_px - pbX_px  ; Reduce CanvasGadgetWidth by its X position.
  ; Foreground progress amount
  VectorSourceColor(BGColor)
  AddPathBox(0, GadgetHeight(gN) - pbHt_px, show_pc*pbWd_px/100, pbHt_px)
  FillPath()
  ; Centered progress text
  MovePathCursor(pbWd_px/2-tW/2, (pbHt_px-tH)/2)
  VectorSourceColor(#aBlack)
  DrawVectorText(s$)
  StopVectorDrawing()
EndProcedure
Procedure.i gad_BGclr(gN.i, txt$, Show_pc.i=100, BGColor.i=#aGreenLight)
  Protected.i gWd = GadgetWidth(gN)
  Protected.i gHt = GadgetHeight(gN)
  Static.i imgN
  If IsImage(imgN)
    FreeImage(imgN)
  EndIf
  imgN = CreateImage(#PB_Any, gWd+2, gHt)
  StartDrawing(ImageOutput(ImgN))
  Box(0, 0, gWd, gHt, GetGadgetColor(gN, #PB_Gadget_FrontColor)) ; Background
  Box(0, 0, gWd, gHt, #GrayLight)                                ; Background
  Box(0, 0, gWd*Show_pc/100, gHt, BGColor)                       ; Foreground Progress Amount
  DrawingMode(#PB_2DDrawing_Transparent)
  DrawingFont(fntC)
  Protected.i tW = TextWidth(txt$)
  Protected.i tH = TextHeight(txt$)
  DrawText(gWd/2 - tW/2, (gHt-tH)/2, txt$, #Black)
  StopDrawing()
  ProcedureReturn ImageID(imgN)
EndProcedure
If OpenWindow(0, #PB_Ignore, #PB_Ignore, 640, 480, "Not StatusbarGadget", #PB_Window_SizeGadget | #PB_Window_SystemMenu)
  ContainerGadget(0, 0, 0, 350, 28, #PB_Container_Single)
  StringGadget(1, 0, 0, 180, 24, "Status", #PB_String_BorderLess | #PB_Text_Center)
  SetGadgetColor(1, #PB_Gadget_BackColor, #GrayLight)
  ButtonImageGadget(2, 184, 0, 48, 24, 0)
  CanvasGadget(3, 184 + 48 + 4, 0, 350, 24)
  CloseGadgetList()
  SetGadgetFont(1, fntC)
  SetGadgetFont(2, fntC)
  GadgetToolTip(3, "Statusbar progress")
  GadgetToolTip(1, "Editable Statusbar")
  ButtonGadget(4, 405, 10, 50, 25, "Done")
  SetGadgetAttribute(3, #PB_Canvas_Cursor, #PB_Cursor_Cross)
  SetGadgetFont(4, fntC)
  ResizeGadget(0, 0, WindowHeight(0) - 24, WindowWidth(0)-8, 24)  ; Force repaint to show container.
  ResizeGadget(3, #PB_Ignore, #PB_Ignore, GadgetWidth(0), #PB_Ignore)
  SetGadgetAttribute(2, #PB_Button_Image, gad_BGclr(2, "OK?", 100, #YellowLight))
  Repeat
    Select WaitWindowEvent(10)
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      evG = EventGadget()
      If evG = 0
      ElseIf evg = 2
        If Random(1,0)
          SetGadgetAttribute(2, #PB_Button_Image, gad_BGclr(2, "OK?", 100, #aGreenLight))
          gad_ProgressBarTextV(3, Random(100),"",24, #aGreenLight)
        Else
          SetGadgetAttribute(2, #PB_Button_Image, gad_BGclr(2, "OK?", 100, #aRedLight))
          gad_ProgressBarTextV(3, Random(100),"",24, #aRedLight)
        EndIf
      ElseIf evG = 3
        gad_ProgressBarTextV(3, Random(100),"",24, #aGreenLight)
      ElseIf evG = 4
        gad_ProgressBarTextV(3, 100, "Done",24, #aGreenLight)
      EndIf
    Case #PB_Event_SizeWindow
      ResizeGadget(0, 0, WindowHeight(0) - 24, WindowWidth(0)-8, 24)
      ResizeGadget(3, #PB_Ignore, #PB_Ignore, GadgetWidth(0), #PB_Ignore)
    EndSelect
  ForEver
EndIf
Last edited by skywalk on Mon Apr 15, 2019 2:54 am, edited 4 times in total.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Gérard
User
User
Posts: 43
Joined: Sat Oct 17, 2015 6:00 pm
Location: France
Contact:

Re: StatusBar: #PB_Event_LeftClick

Post by Gérard »

Hello

Put all your gadgets in a CanvasGadget ()

Code: Select all

CanvasGadget (#canvas, 0, 0, #appWidth, #appWidth, #PB_Canvas_Container)
StartDrawing (CanvasOutput (#canvas))
    FillArea (0, 0,-1, #bgcolor)
StopDrawing ()

; Add gadgets here

CloseGadgetList ()
■ Win10 64-bit (Intel Celeron CPU N2920 @ 1.86GHz, 4,0GB RAM, Intel HD Graphics) & PB 6.00 LTS
■ Vivre et laisser vivre.
■ PureBasic pour le fun
■ cage sur le forum Français
■ Mes sites: http://pbcage.free.fr - http://yh.toolbox.free.fr
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: StatusBar: #PB_Event_LeftClick

Post by Dude »

Marc56us wrote:I suggested a native function.
+1
Post Reply