November 25, 2020, 05:41:15 AM

Author Topic: [bmx] .Net-style Toolbars by JoshK [ 1+ years ago ]  (Read 821 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] .Net-style Toolbars by JoshK [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : .Net-style Toolbars
Author : JoshK
Posted : 1+ years ago

Description : This gives you a modern .NET-style toolbar.  Just import this file into your program and go.  Unfortunately you have to adjust the positions of your other gadgets in the window, but it's worth it.
[img]www.leadwerks.com/post/beautybars.html">


Code :
Code: BlitzMax
  1. SuperStrict
  2. Import maxgui.drivers
  3. Import maxgui.maxgui
  4. Import brl.pixmap
  5. ?win32
  6. Import pub.win32
  7. ?
  8.  
  9. Function CreateToolbar:TGadget(source:Object,x:Int,y:Int,width:Int,height:Int,group:TGadget,style:Int=0)
  10.         ?macos
  11.         Return maxgui.maxgui.CreateToolbar(source,x,y,width,height,group,style)
  12.         ?
  13.         ?win32
  14.         Local color:Int
  15.         Local b:Byte[4]
  16.         Local bt:Byte[4]
  17.         Local pixmap:TPixmap
  18.         Local panel:TGadget
  19.         Local gradient:TPixmap
  20.         Local toolbarheight:Int
  21.         Local btncolor:Int
  22.        
  23.         btncolor=GetSysColor(COLOR_BTNFACE)
  24.         MemCopy bt,Varptr btncolor,4
  25.                        
  26.         pixmap=TPixmap(source)
  27.         If Not pixmap pixmap=LoadPixmap(source)
  28.         If Not pixmap Return Null
  29.        
  30.         toolbarheight=pixmap.height+8
  31.        
  32.         panel=CreatePanel(0,0,group.ClientWidth(),toolbarheight,group)
  33.         panel.SetLayout 1,1,1,0
  34.         Local toolbar:TGadget=maxgui.maxgui.CreateToolbar(source,x,y,width,height,panel,style)
  35.         gradient=CreatePixmap(1,toolbarheight,PF_RGBA8888)
  36.         For Local px:Int=0 To gradient.width-1
  37.                 For Local py:Int=0 To gradient.height-1
  38.                         color=gradient.ReadPixel(px,py)
  39.                         MemCopy b,Varptr color,4
  40.                         Local m#
  41.                         Local factor#=0.9'make this bigger (but less than one) for a less visible gradient
  42.                         m=(1.0-Float(py)/Float(gradient.height))*(1.0-factor)+factor
  43.                         m=Min(1.0,m)
  44.                         If py=gradient.height-1 m=factor*0.85
  45.                         b[0]=bt[2]*m
  46.                         b[1]=bt[1]*m
  47.                         b[2]=bt[0]*m
  48.                         b[3]=255
  49.                         MemCopy Varptr color,b,4
  50.                         gradient.WritePixel px,py,color
  51.                 Next
  52.         Next
  53.         SetGadgetPixmap panel,gradient
  54.         Return toolbar
  55.         ?
  56. EndFunction
  57.  
  58. Rem
  59.  
  60. 'Example
  61.  
  62. AppTitle = "ToolBar Example"
  63.  
  64. Global window:TGadget = CreateWindow( AppTitle, 100, 100, 600, 300, Null, WINDOW_TITLEBAR|WINDOW_STATUS|WINDOW_RESIZABLE|WINDOW_CLIENTCOORDS )
  65.  
  66. Global toolbar:TGadget = CreateToolbar( "toolbar.png", 0, 0, 0, 0, window )
  67. DisableGadgetItem toolbar, 2
  68.  
  69. SetToolbarTips toolbar, ["New", "Open", "Save should be disabled."]
  70.  
  71. AddGadgetItem toolbar, "", 0, GADGETICON_SEPARATOR      'Add a separator.
  72. AddGadgetItem toolbar, "Toggle", GADGETITEM_TOGGLE, 2, "This toggle button should change to a light bulb when clicked."
  73.  
  74. While WaitEvent()
  75.         Print CurrentEvent.ToString()
  76.         Select EventID()
  77.                 Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE;End
  78.                 'ToolBar Event(s)
  79.                 'EventData() holds the index of the toolbar item clicked.
  80.                 Case EVENT_GADGETACTION
  81.                         Select EventSource()
  82.                                 Case toolbar
  83.                                         SetStatusText window, "Toolbar Item Clicked: " + EventData()
  84.                         EndSelect
  85.         End Select
  86. Wend
  87.  
  88. endrem


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal