Basis for a cool Status/Tool bar

Share your advanced PureBasic knowledge/code with the community.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Basis for a cool Status/Tool bar

Post by netmaestro »

Code updated For 5.20+

This code doesn't accomplish much in and of itself but if someone wanted to use it as the basis for a status bar for jobs that take time it would work well for that. Maybe put a ProgressBar gadget on it. Or you could put icons on it for a toolbar, or wire links into the menu. It's a starting point really for a number of possibilities. I just made it for fun, thought it was cool and so I'm sharing it. Hope you like it.

Code: Select all

Enumeration
  #windowmain
  #windowimage
  #closebutton
  #buttonimage
  #hotbuttonimage
  #menuclose
EndEnumeration

Global windowalpha = 70
Global Days$="Sun Mon Tue Wed Thu Fri Sat"
Global months$="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"

Procedure Fadein()
  While windowalpha < 220
    windowalpha+10
    SetLayeredWindowAttributes_(WindowID(#windowmain),0,windowalpha,#LWA_ALPHA)
    Delay(1)
  Wend
EndProcedure

Procedure Fadeout()
  While windowalpha > 70
    windowalpha-10
    SetLayeredWindowAttributes_(WindowID(#windowmain),0,windowalpha,#LWA_ALPHA)
    Delay(1)
  Wend
EndProcedure

Procedure ProcessHotSpots()
  Select ChildWindowFromPoint_(WindowID(#windowmain),(WindowMouseX(#windowmain) & $FFFFFFFF) | (WindowMouseY(#windowmain)) << 32);,,
    Case GadgetID(#closebutton)
      SetGadgetState(#closebutton, ImageID(#hotbuttonimage))
    Case WindowID(#windowmain)
      SetGadgetState(#closebutton, ImageID(#buttonimage))
  EndSelect
EndProcedure

CreateImage(#windowimage,400,28)
StartDrawing(ImageOutput(#windowimage))
Line(0,0,1,28,#Black)
Line(399,0,1,28,#Black)
For j=1 To 398
  Restore windowface
  For i=0 To 27
    Read color
    Plot(j,i,color)
  Next
Next
StopDrawing()
GrabImage(#windowimage,#buttonimage,370,6,20,18)
StartDrawing(ImageOutput(#buttonimage))
DrawingMode(3)
DrawText(6,1,"X",RGB(160,20,160))
StopDrawing()
GrabImage(#windowimage,#hotbuttonimage,370,6,20,18)
StartDrawing(ImageOutput(#hotbuttonimage))
DrawingMode(3)
DrawText(6,1,"X",#White)
DrawText(7,1,"X",#White)
StopDrawing()

ExamineDesktops()
OpenWindow(#windowmain,DesktopWidth(0)-440,DesktopHeight(0)/2-10,400,28,"",#PB_Window_BorderLess)
ShowWindow_(WindowID(#windowmain),#SW_HIDE)
SetWindowLong_(WindowID(#windowmain),#GWL_EXSTYLE,GetWindowLong_(WindowID(#windowmain),#GWL_EXSTYLE)|#WS_EX_LAYERED|#WS_EX_TOOLWINDOW)
SetLayeredWindowAttributes_(WindowID(#windowmain),0,windowalpha,#LWA_ALPHA)
ShowWindow_(WindowID(#windowmain),#SW_SHOW)
StickyWindow(#windowmain,1)
SmartWindowRefresh(#windowmain,1)


ImageGadget(#closebutton,370,5,20,18,ImageID(#buttonimage))
CreatePopupMenu(0)     
MenuItem(1, "Do valuable task #one") 
MenuItem(2, "Do valuable task #two")
MenuItem(3, "Do valuable task #three")
MenuItem(#menuclose, "Close the toolbar")
quit=0

time=ElapsedMilliseconds()
Repeat
  day$=StringField(days$,DayOfWeek(Date())+1," ")+" "
  mon$=StringField(months$,Month(Date())," ")+" "
  If Hour(Date())<12
    ampm$="am"
    hour=Hour(Date())
  Else
    ampm$="pm"
    hour=Hour(Date())-12
  EndIf
  hour$=Str(hour)+ ":"
  daynum$=Str(Day(Date()))+" "
  min$=RSet(Str(Minute(Date())),2,"0")+" "
  date$=day$+mon$+daynum$+hour$+min$+ampm$
  If ElapsedMilliseconds()-time >= 5000
    time=ElapsedMilliseconds()
    InvalidateRgn_(WindowID(#windowmain),0,0) 
  EndIf
  EventID=WaitWindowEvent(1)
  Select EventID
    Case #PB_Event_ActivateWindow, #WM_PAINT
      StartDrawing(WindowOutput(#windowmain))
      DrawImage(ImageID(#windowimage),0,0)
      DrawingMode(3)
      DrawText(10,5, date$ )
      StopDrawing()
      InvalidateRgn_(WindowID(#windowmain),0,0)  ;uncomment if gadgets exist
      UpdateWindow_(WindowID(#windowmain))
    Case #WM_LBUTTONDOWN
      SendMessage_(WindowID(#windowmain), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
    Case #WM_RBUTTONDOWN     
      DisplayPopupMenu(0, WindowID(#windowmain))
    Case #PB_Event_Menu
      Select EventMenu()
        Case #menuclose
          quit=1
      EndSelect
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #closebutton
          quit = 1
      EndSelect
  EndSelect
  If DesktopMouseX()>=WindowX(#windowmain) And DesktopMouseX()<=WindowX(#windowmain)+ImageWidth(#windowimage)
    If DesktopMouseY()>=WindowY(#windowmain) And DesktopMouseY()<=WindowY(#windowmain)+ImageHeight(#windowimage)
      Fadein()
    Else
      Fadeout()
    EndIf
  Else
    Fadeout()
  EndIf 
  ProcessHotSpots()
Until quit
End

DataSection
  windowface:
  Data.l $0,$C0BBC9,$BEB8C9,$BEB5C9,$BCB1C9,$BAADC9,$B9A9C9,$B7A5C9,$B6A0C7,$B49CC8,$B297C7,$B092C7,$AD8DC7,$AC87C6
  Data.l $A982C6,$A87DC5,$A578C5,$A372C5,$A16CC4,$9F67C4,$9D63C3,$9B5DC3,$9959C2,$9754C2,$954FC2,$944BC1,$9347C1,$0
EndDataSection

Oh yes, I forgot, if you are going to use this you might want to put a different face on it. I made a little tool that will create the datasection from an image you've made in Photoshop or similar, it will speed up the process quite a bit.

Code: Select all

Dim colors.s(28)
LoadImage(0,"windowface.bmp")
StartDrawing(ImageOutput(0))
  For i = 0 To 27
    colors(i)="$"+Hex(Point(5,i))
  Next
StopDrawing()
CreateFile(0,"windowface.pbi")

WriteStringN(0,"DataSection")
WriteStringN(0,"  windowface:")

WriteString(0,"  Data.l ")
For i = 0 To 12
  WriteString(0,colors(i)+",")
Next
WriteStringN(0,colors(13))
WriteString(0,"  Data.l ")
For i = 14 To 26
  WriteString(0,colors(i)+",")
Next
WriteStringN(0,colors(27))
WriteStringN(0,"EndDataSection")

CloseFile(0)
Last edited by netmaestro on Sun Mar 05, 2006 3:42 pm, edited 1 time in total.
BERESHEIT
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

This is very nice - lots of possibilities here.

Many thanks for sharing this code.

cheers
techjunkie
Addict
Addict
Posts: 1126
Joined: Wed Oct 15, 2003 12:40 am
Location: Sweden
Contact:

Post by techjunkie »

Great! and very cool! any ideas how to make it dockable? :lol:
Image
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Wow, you must be some kind of mind reader. I've just finished working on exactly that. Tell me what you have in mind as to docking and I'll see how closely it fits with what I've been doing.
BERESHEIT
techjunkie
Addict
Addict
Posts: 1126
Joined: Wed Oct 15, 2003 12:40 am
Location: Sweden
Contact:

Post by techjunkie »

netmaestro wrote:Wow, you must be some kind of mind reader. I've just finished working on exactly that. Tell me what you have in mind as to docking and I'll see how closely it fits with what I've been doing.
Well, I was thinking about "Ordinary Desktop Docking Behaviour" (ODDB). Hehe... :wink:

When you drag it near bottom or top Desktop edge it snaps to the edge and if you drag it to the Desktop right or left side it snaps to the edge but vertically.

Maybe something like that...

[EDIT]

I'll guess the vertical stuff is a lot harder to do and to get nice looking.
Image
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Yes, the vertical stuff is a lot more work. What I had in mind for "side-docking" was that if you dragged the bar past the edge of the window very far, say half an inch, or maybe an inch, it would dart mostly off the screen so only half an inch shows. Then, when you hover over the visible part, it slides out all the way and sits there until about 2 seconds after you stop interacting with it. Then it slides back. Of course the top-and-bottom stuff is really easy. I actually had it working that way at one point, but scaled it back for sharing. Trouble is, I didn't keep the code!
BERESHEIT
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post by mskuma »

netmaestro, thanks alot for sharing this - it will be a great learning piece!
Post Reply