Create your own icons for toolbars etc. with PureBasic

Share your advanced PureBasic knowledge/code with the community.
davido
Addict
Addict
Posts: 1841
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Create your own icons for toolbars etc. with PureBasic

Post by davido »

Hi Little John,
Nice picture. :)
Thank you for the update and improvements.

Hi Oma,
I've just taken a close look at your latest icons: They are incredible!
You have produced a lovely set of professional looking icons. Congratulations.
DE AA EB
davido
Addict
Addict
Posts: 1841
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Create your own icons for toolbars etc. with PureBasic

Post by davido »

Hi Little John,

I have two more simple icons to offer: Battery Charging and Snowflake
Battery Charging uses a Macro to generate the 'charge'.

Code: Select all

Declare.i BatteryCharging (file$, img.i, size.i, color1.i, color2.i, color3.i)
Declare.i Snowflake (file$, img.i, size.i, color.i)

   Macro ChargeFlash(_x_,_y_,_size_)
     MovePathCursor(_x_ + 0.09375*_size_,_y_-0.4375*_size_)
     AddPathLine(_x_-0.21875*_size_,_y_ +0.0625*_size_)
     AddPathLine(_x_-0.0625*_size_,_y_+0.0625*_size_)
     AddPathLine(_x_-0.0625*_size_,_y_+0.4375*_size_)
     AddPathLine(_x_+0.25*_size_,_y_-0.0625*_size_)
     AddPathLine(_x_ + 0.09375*_size_,_y_-0.0625*_size_)
     ClosePath()
     FillPath()
   EndMacro
   
   Procedure.i BatteryCharging (file$, img.i, size.i, color1.i, color2.i, color3.i)
     ; file$: name of SVG file which is to be created (only supported on Linux),
     ;        or "" for creating an image in memory
     ; in : img   : number of the image which is to be created, or #PB_Any
     ;      size  : width and height (number of pixels)
     ;      color1: foreground color #1
     ;      color2: foreground color #2
     ;      color3: foreground color #3
     ; out: return value: if img = #Pb_Any => number of the created image,
     ;                    error => 0
     
     ; [by davido]
     Protected ret.i, p.d
     
     ret = StartVectorIconOutput(file$, img, size)
     
     p = size / 32.0
     
     If ret
       VectorSourceColor(color1)
       DrawRoundBox(14*p,4*p,4*p,3*p,1*p)
       FillPath()
       VectorSourceColor(color2)
       DrawRoundBox(9*p,6*p,14*p,24*p,2*p)
       FillPath()
       VectorSourceColor(color3)
       ChargeFlash(16*p,18*p,18*p)
       FillPath()
       StopVectorDrawing()
     EndIf
     
     ProcedureReturn ret
   EndProcedure
   
   
Procedure.i Snowflake (file$, img.i, size.i, color.i)
     ; file$: name of SVG file which is to be created (only supported on Linux),
     ;        or "" for creating an image in memory
     ; in : img   : number of the image which is to be created, or #PB_Any
     ;      size  : width and height (number of pixels)
      ;      color: foreground color
      ; out: return value: if img = #Pb_Any => number of the created image,
      ;                    error => 0

      ; [by davido]
      Protected ret.i, p.d, M.i

      ret = StartVectorIconOutput(file$, img, size)

      p = size / 32.0

      If ret
        VectorSourceColor(color)
        For M = 1 To 6
          MovePathCursor(16*p,16*p)
          AddPathLine(16*p,2*p)
          MovePathCursor(20*p,3*p)
          AddPathLine(16*p,8*p)
          AddPathLine(12*p,3*p)
          RotateCoordinates(16*p,16*p,60)
          StrokePath(2*p,#PB_Path_RoundEnd)
        Next M
         StopVectorDrawing()
      EndIf

      ProcedureReturn ret
    EndProcedure
    
    "Battery Charging", "Snowflake"
    
    NewIcon( BatteryCharging (file$, img.i, size.i, #CSS_Grey, #CSS_Black, #CSS_Yellow))
    NewIcon( Snowflake (file$, img.i, size.i, #CSS_Black))
    
    NewIcon( BatteryCharging (file$, img.i, size.i, #CSS_Grey, #CSS_Silver, #CSS_WhiteSmoke))
    NewIcon( Snowflake (file$, img.i, size.i, #CSS_Silver))
DE AA EB
Little John
Addict
Addict
Posts: 3981
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Create your own icons for toolbars etc. with PureBasic

Post by Little John »

Nice davido, thank you!
Collection updated.
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups
davido
Addict
Addict
Posts: 1841
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Create your own icons for toolbars etc. with PureBasic

Post by davido »

Hi Little John,
I had second thoughts about adding extra parameters, so I revised my upper-case font to use a macro instead.

Code: Select all

Declare.i A2M (file$, img.i, size.i, color.i)
Declare.i N2Z (file$, img.i, size.i, color.i)

   Macro UcaseFont(_x_,_y_,_size_,_Char_,_rotation_=0)
     hh = _size_ *0.3125
     SaveVectorState()
     RotateCoordinates(size * 0.5,size * 0.5,_rotation_)
     Select _Char_
       Case Asc("A") 
         hw = hh * 0.9
         MovePathCursor(_x_ - hw,_y_ + hh)
         AddPathLine(_x_,_y_ - hh)
         AddPathLine(_x_ + hw, _y_ + hh)
         MovePathCursor(_x_ - hw/1.8,_y_ + hh/3)
         AddPathLine(_x_ + hw/1.8,_y_ + hh/3)
         
       Case Asc("B")
         hw = hh * 0.81
         MovePathCursor(_x_ + hw * 0.08,_y_ - hh)
         AddPathLine(_x_ - hw ,_y_ - hh)
         AddPathLine(_x_ - hw, _y_ + hh)
         MovePathCursor(_x_ - hw + hh,_y_)
         AddPathLine(_x_ - hw,_y_)
         AddPathCircle(_x_ + hw * 0.08,_y_ - hh/2,hh/2,270,90)
         MovePathCursor(_x_ - hw + hh,_y_ + hh)
         AddPathLine(_x_ - hw,_y_ + hh)
         AddPathCircle(_x_ - hw + hh,_y_ + hh/2,hh/2,270,90)
         
       Case Asc("C")
         hw = hh * 0.9
         AddPathCircle(_x_, _y_ + hw - hh,hw,200,340)
         AddPathCircle(_x_, _y_ - hw + hh,hw,20,160)
         MovePathCursor(_x_ - hw * 0.95,_y_ - hh/2.75)
         AddPathLine(_x_ - hw * 0.95,_y_ + hh/2.75)
         
       Case Asc("D")
         hw = hh * 0.81
         MovePathCursor(_x_ - hw/2.5,_y_ - hh)
         AddPathLine(_x_ - hw ,_y_ - hh)
         AddPathLine(_x_ - hw, _y_ + hh)
         MovePathCursor(_x_ - hw/2.5,_y_ + hh)
         AddPathLine(_x_ - hw,_y_ + hh)
         AddPathCircle(_x_ - hw/2.5,_y_ ,hh,270,90)
         
       Case Asc("E")
         hw = hh * 0.81
         MovePathCursor(_x_ + hw,_y_ - hh)
         AddPathLine(_x_ - hw ,_y_ - hh)
         AddPathLine(_x_ - hw, _y_ + hh)
         AddPathLine(_x_ + hw,_y_ + hh)
         MovePathCursor(_x_ - hw,_y_)
         AddPathLine(_x_ + hw * 0.8,_y_)
         
       Case Asc("F")
         hw = hh * 0.81
         MovePathCursor(_x_ + hw,_y_ - hh)
         AddPathLine(_x_ - hw ,_y_ - hh)
         AddPathLine(_x_ - hw, _y_ + hh)
         MovePathCursor(_x_ - hw,_y_)
         AddPathLine(_x_ + hw * 0.8,_y_)
         
       Case Asc("G")
         hw = hh * 0.9
         AddPathCircle(_x_, _y_ + hw - hh,hw,200,340)
         AddPathCircle(_x_, _y_ - hw + hh,hw,20,160)
         MovePathCursor(_x_ - hw * 0.95,_y_ - hh/2.75)
         AddPathLine(_x_ - hw * 0.95,_y_ + hh/2.75)
         MovePathCursor(_x_  + hw/5,_y_  + hh/5)
         AddPathLine(_x_ + hw * 0.95,_y_  + hh/5)
         AddPathLine(_x_ + hw * 0.95,_y_ + hh/2.75)
         
       Case Asc("H")
         hw = hh * 0.81
         MovePathCursor(_x_ - hw,_y_ - hh)
         AddPathLine(_x_ - hw ,_y_ + hh)
         MovePathCursor(_x_ + hw,_y_ - hh)
         AddPathLine(_x_ + hw ,_y_ + hh)
         MovePathCursor(_x_ - hw,_y_)
         AddPathLine(_x_ + hw ,_y_)
         
       Case Asc("I")
         hw = hh * 0.81
         MovePathCursor(_x_ ,_y_ - hh)
         AddPathLine(_x_ ,_y_ + hh)
         
       Case Asc("J") 
         hw = hh * 0.81
         MovePathCursor(_x_ ,_y_ - hh)
         AddPathLine(_x_ ,_y_ + hh * 0.55)
         AddPathCircle(_x_ - hh/2,_y_ + hh/2, hh/2,0,180)
         
       Case Asc("K")
         hw = hh * 0.6
         MovePathCursor(_x_ - hw,_y_ - hh)
         AddPathLine(_x_ - hw,_y_ + hh)
         MovePathCursor(_x_ - hw,_y_ + hh/3)
         AddPathLine(_x_ + hw, _y_ - hh)
         MovePathCursor(_x_ - hw/8,_y_ - hh/10)
         AddPathLine(_x_ + hw,_y_ + hh)
         
       Case Asc("L")
         hw = hh * 0.45
         MovePathCursor(_x_ - hw,_y_ - hh)
         AddPathLine(_x_ - hw ,_y_ + hh)
         AddPathLine(_x_ + hw, _y_ + hh)
         
       Case Asc("M")
         hw = hh * 0.9
         MovePathCursor(_x_ - hw,_y_ + hh)
         AddPathLine(_x_ - hw,_y_ - hh)
         AddPathLine(_x_, _y_ + hh * 0.05)
         AddPathLine(_x_ + hw,_y_ - hh)
         AddPathLine(_x_ + hw,_y_ + hh)
         
       Case Asc("N")
         hw = hh * 0.81
         MovePathCursor(_x_ - hw,_y_ + hh)
         AddPathLine(_x_ - hw ,_y_ - hh)
         AddPathLine(_x_ + hw ,_y_ + hh)
         AddPathLine(_x_ + hw ,_y_ -hh)
         
       Case Asc("O")
         hw = hh * 0.9
         AddPathCircle(_x_, _y_ + hw - hh,hw,200,340)
         AddPathCircle(_x_, _y_ - hw + hh,hw,20,160)
         MovePathCursor(_x_ - hw * 0.95,_y_ - hh/2.75)
         AddPathLine(_x_ - hw * 0.95,_y_ + hh/2.75)
         MovePathCursor(_x_ + hw * 0.95,_y_ - hh/2.75)
         AddPathLine(_x_ + hw * 0.95,_y_ + hh/2.75)
         
       Case Asc("P")
         hw = hh * 0.81
         MovePathCursor(_x_ - hw + hh,_y_ - hh)
         AddPathLine(_x_ - hw ,_y_ - hh)
         AddPathLine(_x_ - hw, _y_ + hh)
         MovePathCursor(_x_ - hw + hh,_y_)
         AddPathLine(_x_ - hw,_y_)
         AddPathCircle(_x_ - hw + hh,_y_ - hh/2,hh/2,270,90)
         
       Case Asc("Q")   
         hw = hh * 0.9
         AddPathCircle(_x_, _y_ + hw - hh,hw,200,340)
         AddPathCircle(_x_, _y_ - hw + hh,hw,20,160)
         MovePathCursor(_x_ - hw * 0.95,_y_ - hh/2.75)
         AddPathLine(_x_ - hw * 0.95,_y_ + hh/2.75)
         MovePathCursor(_x_ + hw * 0.95,_y_ - hh/2.75)
         AddPathLine(_x_ + hw * 0.95,_y_ + hh/2.75)
         MovePathCursor(_x_ + hw/4,_y_ + hh/4)
         AddPathLine(_x_ + hw * 1.1,_y_ + hh * 1.1)
         
       Case Asc("R")
         hw = hh * 0.81
         MovePathCursor(_x_ - hw + hh,_y_ - hh)
         AddPathLine(_x_ - hw ,_y_ - hh)
         AddPathLine(_x_ - hw, _y_ + hh)
         MovePathCursor(_x_ - hw + hh,_y_)
         AddPathLine(_x_ - hw,_y_)
         AddPathCircle(_x_ - hw + hh,_y_ - hh/2,hh/2,270,90)
         MovePathCursor(PathCursorX() - hw/6,PathCursorY())
         AddPathLine(_x_ + hw * 0.7,_y_ + hh)
         
       Case Asc("S")
         hw = hh * 0.9
         AddPathCircle(_x_ + 0.0125 * _size_,_y_ - 0.0125 * _size_, 0.315625 * _size_,240,320)
         AddPathCircle(_x_ - 0.09375 * _size_,_y_ - 0.15625 * _size_, 0.140625 * _size_,250,95,#PB_Path_CounterClockwise)
         AddPathLine(_x_ + 0.125 * _size_, _y_ + 0.046875 * _size_)
         AddPathCircle(_x_ + 0.125 * _size_,_y_ + 0.1875 * _size_, 0.140625 * _size_,275,70)
         AddPathCircle(_x_ + 0.01875 * _size_,_y_ + 0.04375 * _size_, 0.315625 * _size_,60,140)         
         
       Case Asc("T")
         hw = hh * 0.81
         MovePathCursor(_x_ - hw,_y_ - hh)
         AddPathLine(_x_ + hw ,_y_ - hh)
         MovePathCursor(_x_, _y_ - hh)
         AddPathLine(_x_,_y_ + hh)
         
       Case Asc("U")
         hw = hh * 0.81
         AddPathCircle(_x_, _y_ - hw + hh,hw,20,160)
         MovePathCursor(_x_ - hw * 0.95,_y_ - hh)
         AddPathLine(_x_ - hw * 0.95,_y_ + hh/2.3)
         MovePathCursor(_x_ + hw * 0.95,_y_ - hh)
         AddPathLine(_x_ + hw * 0.95,_y_ + hh/2.3)
         
       Case Asc("V")
         hw = hh * 0.9
         MovePathCursor(_x_ - hw,_y_ - hh)
         AddPathLine(_x_ ,_y_ + hh)
         AddPathLine(_x_ + hw, _y_ - hh)
         
       Case Asc("W")
         hw = hh * 1.5
         MovePathCursor(_x_ - hw, _y_ - hh)
         AddPathLine(_x_ - hw * 0.5,_y_ + hh)
         AddPathLine(_x_,_y_ - hh * 0.5)
         AddPathLine(_x_ + hw * 0.5,_y_ + hh)
         AddPathLine(_x_ + hw,_y_ - hh)
         
       Case Asc("X")
         hw = hh * 0.81
         MovePathCursor(_x_ - hw,_y_ - hh)
         AddPathLine(_x_ + hw ,_y_ + hh)
         MovePathCursor(_x_ + hw, _y_ - hh)
         AddPathLine(_x_ - hw,_y_ + hh)
         
       Case Asc("Y")
         hw = hh * 0.9
         MovePathCursor(_x_ - hw,_y_ - hh)
         AddPathLine(_x_ ,_y_)
         AddPathLine(_x_ + hw, _y_ - hh)
         MovePathCursor(_x_,_y_)
         AddPathLine(_x_,_y_ + hh)
         
       Case Asc("Z")
         hw = hh * 0.81
         hw = hh * 0.81
         MovePathCursor(_x_ - hw,_y_ - hh)
         AddPathLine(_x_ + hw ,_y_ - hh)
         AddPathLine(_x_ - hw, _y_ + hh)
         AddPathLine(_x_ + hw,_y_ + hh)
         
     EndSelect
     StrokePath(_size_ / 16,#PB_Path_RoundEnd | #PB_Path_RoundCorner)
     RestoreVectorState()
   EndMacro



   Procedure.i A2M (file$, img.i, size.i, color.i)
     ; file$: name of SVG file which is to be created (only supported on Linux),
     ;        or "" for creating an image in memory
     ; in : img   : number of the image which is to be created, or #PB_Any
     ;      size  : width and height (number of pixels)
     ;      color: foreground color
     ; out: return value: if img = #Pb_Any => number of the created image,
     ;                    error => 0
     
     ; [by davido]
     Protected ret.i, p.d, hh.d, hw.d, M.i
     
     ret = StartVectorIconOutput(file$, img, size)
     
     p = size / 32.0
     
     If ret
       VectorSourceColor(color)
         UcaseFont(size * 0.125,size * 0.125,size * 0.25,Asc("A"))
         UcaseFont(size * 0.375,size * 0.125,size * 0.25,Asc("B"))
         UcaseFont(size * 0.625,size * 0.125,size * 0.25,Asc("C"))
         UcaseFont(size * 0.875,size * 0.125,size * 0.25,Asc("D"))
         UcaseFont(size * 0.125,size * 0.375,size * 0.25,Asc("E"))
         UcaseFont(size * 0.375,size * 0.375,size * 0.25,Asc("F"))
         UcaseFont(size * 0.625,size * 0.375,size * 0.25,Asc("G"))
         UcaseFont(size * 0.875,size * 0.375,size * 0.25,Asc("H"))
         UcaseFont(size * 0.125,size * 0.625,size * 0.25,Asc("I"))
         UcaseFont(size * 0.375,size * 0.625,size * 0.25,Asc("J"))
         UcaseFont(size * 0.625,size * 0.625,size * 0.25,Asc("K"))
         UcaseFont(size * 0.875,size * 0.625,size * 0.25,Asc("L"))
         UcaseFont(size * 0.125,size * 0.875,size * 0.25,Asc("M")) 
       StopVectorDrawing()
     EndIf

      ProcedureReturn ret
    EndProcedure
    
Procedure.i N2Z (file$, img.i, size.i, color.i)
     ; file$: name of SVG file which is to be created (only supported on Linux),
     ;        or "" for creating an image in memory
     ; in : img   : number of the image which is to be created, or #PB_Any
     ;      size  : width and height (number of pixels)
      ;      color: foreground color
      ; out: return value: if img = #Pb_Any => number of the created image,
      ;                    error => 0

      ; [by davido]
      Protected ret.i, p.d, hh.d, hw.d

      ret = StartVectorIconOutput(file$, img, size)

      p = size / 32.0

      If ret
         VectorSourceColor(color)
         UcaseFont(size * 0.125,size * 0.125,size * 0.25,Asc("N"))
         UcaseFont(size * 0.375,size * 0.125,size * 0.25,Asc("O"))
         UcaseFont(size * 0.625,size * 0.125,size * 0.25,Asc("P"))
         UcaseFont(size * 0.875,size * 0.125,size * 0.25,Asc("Q"))
         UcaseFont(size * 0.125,size * 0.375,size * 0.25,Asc("R"))
         UcaseFont(size * 0.375,size * 0.375,size * 0.25,Asc("S"))
         UcaseFont(size * 0.625,size * 0.375,size * 0.25,Asc("T"))
         UcaseFont(size * 0.875,size * 0.375,size * 0.25,Asc("U"))
         UcaseFont(size * 0.125,size * 0.625,size * 0.25,Asc("V"))
         UcaseFont(size * 0.375,size * 0.625,size * 0.25,Asc("W"))
         UcaseFont(size * 0.625,size * 0.625,size * 0.25,Asc("X"))
         UcaseFont(size * 0.875,size * 0.625,size * 0.25,Asc("Y"))
         UcaseFont(size * 0.125,size * 0.875,size * 0.25,Asc("Z"))
         StopVectorDrawing()
      EndIf

      ProcedureReturn ret
    EndProcedure
    
    
    , "N2Z", "A2M"
    

NewIcon( A2M (file$, img.i, size.i, #CSS_Blue))
NewIcon( N2Z (file$, img.i, size.i, #CSS_Blue))

NewIcon( A2M (file$, img.i, size.i, #CSS_Silver))
NewIcon( N2Z (file$, img.i, size.i, #CSS_Silver))
















DE AA EB
Little John
Addict
Addict
Posts: 3981
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Create your own icons for toolbars etc. with PureBasic

Post by Little John »

Thank you, davido!

Current changes
  • Added icons "A2M" and "N2Z" by davido
  • In the icon browser, the icons can now be zoomed.
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups
davido
Addict
Addict
Posts: 1841
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Create your own icons for toolbars etc. with PureBasic

Post by davido »

Hi Little John,
Thank you for including my latest icons.
The zoom facility is an excellent addition.
DE AA EB
Little John
Addict
Addict
Posts: 3981
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Create your own icons for toolbars etc. with PureBasic

Post by Little John »

Current changes
  • Procedures Spray_Spatial() and Spray_Flat() updated by Oma.
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups
Little John
Addict
Addict
Posts: 3981
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Create your own icons for toolbars etc. with PureBasic

Post by Little John »

Current changes
Improvements in the file "vectoriconbrowser.pb":
  • Now PureBasic's Dialog library is used, so
    • The GUI is better cross-platform compatible.
    • The window is resizable.
  • Other small improvements.
  • Code tidied up.
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups
davido
Addict
Addict
Posts: 1841
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Create your own icons for toolbars etc. with PureBasic

Post by davido »

Hi Little John,

Perfect.
Looks great on my MacBook, now.
DE AA EB
Little John
Addict
Addict
Posts: 3981
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Create your own icons for toolbars etc. with PureBasic

Post by Little John »

davido wrote:Looks great on my MacBook, now.
Hi davido,

I'm glad to read that. Thank you for reporting it!
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups
davido
Addict
Addict
Posts: 1841
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Create your own icons for toolbars etc. with PureBasic

Post by davido »

Hi Little John,
I have a few more icons in the making which I will be posting over the next few weeks.
However, PureBasic 5.50 has appeared and I always change to the latest version, because I can. I appreciate that others may not be so fortunate.

Could you please consider what version of PureBasic you would want your code to comply with?
DE AA EB
Little John
Addict
Addict
Posts: 3981
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Create your own icons for toolbars etc. with PureBasic

Post by Little John »

Hi davido,

that's a good question. :-)

It would be OK for me, personally, if the icon library is always compliant with the newest final PB version (I don't want to rely on beta versions).
However, I would like to read other opinions -- especially those of other poeple who contributed to the library.
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups
Little John
Addict
Addict
Posts: 3981
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Create your own icons for toolbars etc. with PureBasic

Post by Little John »

Hi davido!

Since nobody else wrote an opinion about this point ... I'd like the code always to comply with the newest final PureBasic version.
Is that OK with you?
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups
walbus
Addict
Addict
Posts: 930
Joined: Sat Mar 02, 2013 9:17 am

Re: Create your own icons for toolbars etc. with PureBasic

Post by walbus »

Very good work...
davido
Addict
Addict
Posts: 1841
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Create your own icons for toolbars etc. with PureBasic

Post by davido »

Hi Little John,

Little John wrote: Since nobody else wrote an opinion about this point ... I'd like the code always to comply with the newest final PureBasic version.
Is that OK with you?
Eminently satisfactory, thank you.

I would like at offer a couple of new icons:
Rain Cloud and Cloud Storage

Code: Select all

Declare.i RainCloud (file$, img.i, size.i, color1.i, color2.i=0)
Declare.i CloudStorage (file$, img.i, size.i, color1.i, color2.i=0)

   Macro DrawCloud(_x_,_y_,_size_,_outline_=0)
     MovePathCursor(_x_ + 0.375 * _size_,_y_ + 0.375 * _size_)
     AddPathLine(_x_ - 0.375 * _size_,_y_ + 0.375 * _size_)
     AddPathCircle(_x_ - 0.21825 * _size_,_y_ + 0.21825 * _size_,0.221875 * _size_,138,225.25)
     AddPathCircle(_x_ - 0.15625 * _size_,_y_,0.21875 * _size_,166,270,#PB_Path_Connected)
     AddPathCircle(_x_ + 0.03125 * _size_,_y_ - 0.125 * _size_,0.20625 * _size_,207,15,#PB_Path_Connected)
     AddPathCircle(_x_ + 0.1875 * _size_,_y_ + 0.1953125 * _size_,0.2625 * _size_,280,42,#PB_Path_Connected)
     ClosePath()
     If _outline_ = #False
       FillPath(#PB_Path_Preserve)
     EndIf
     StrokePath(p,#PB_Path_RoundEnd) 
   EndMacro
   
   Macro DrawBalloon(_x_,_y_,_size_,_rotation_=0)
     SaveVectorState()
     RotateCoordinates(size * 0.5,size * 0.5,_rotation_)
     MovePathCursor(_x_,_y_ + _size_ * 0.4375)
     AddPathCurve(_x_ - _size_ * 1.125,_y_ - _size_ *0.71875,_x_ + _size_ * 1.125,_y_ - _size_ *0.71875,_x_,_y_ + _size_ * 0.4375)
     StrokePath(_size_ / 32,#PB_Path_RoundEnd | #PB_Path_RoundCorner | #PB_Path_Preserve)
     FillPath()
     RestoreVectorState()
   EndMacro



Procedure.i RainCloud (file$, img.i, size.i, color1.i, color2.i=0)
     ; file$: name of SVG file which is to be created (only supported on Linux),
     ;        or "" for creating an image in memory
     ; in : img   : number of the image which is to be created, or #PB_Any
     ;      size  : width and height (number of pixels)
      ;      color1: foreground color #1
      ;      color2: foreground color #2
      ; out: return value: if img = #Pb_Any => number of the created image,
      ;                    error => 0

      ; [by davido]
      Protected ret.i, p.d

      ret = StartVectorIconOutput(file$, img, size)

      p = size / 32.0

      If ret
        VectorSourceColor(color1)
        DrawCloud(16*p,12*p,size/1.25,1)
        VectorSourceColor(color2)
        DrawBalloon(24*p,4*p,size/8,180)
        DrawBalloon(20*p,8*p,size/9,180)
        DrawBalloon(16*p,4*p,size/8,180)
        DrawBalloon(12*p,8*p,size/9,180)
        DrawBalloon(8*p,4*p,size/8,180)
        StopVectorDrawing()
      EndIf
      
      ProcedureReturn ret
    EndProcedure
    
Procedure.i CloudStorage (file$, img.i, size.i, color1.i, color2.i=0)
     ; file$: name of SVG file which is to be created (only supported on Linux),
     ;        or "" for creating an image in memory
     ; in : img   : number of the image which is to be created, or #PB_Any
     ;      size  : width and height (number of pixels)
      ;      color1: foreground color #1
      ;      color2: foreground color #2
      ; out: return value: if img = #Pb_Any => number of the created image,
      ;                    error => 0

      ; [by davido]
      Protected ret.i, p.d

      ret = StartVectorIconOutput(file$, img, size)

      p = size / 32.0

      If ret
        VectorSourceColor(color1)
        DrawCloud(16*p,12*p,size)
        VectorSourceColor(color2)
        MovePathCursor(6*p,13*p)
        AddPathLine(6*p,19*p)
        AddPathEllipse(11*p,16*p,2*p,2.5*p)
        MovePathCursor(16*p,13*p)
        AddPathLine(16*p,19*p)
        AddPathEllipse(21*p,16*p,2*p,2.5*p)
        MovePathCursor(26*p,13*p)
        AddPathLine(26*p,19*p)
        StrokePath(P)
        StopVectorDrawing()
      EndIf
      
      ProcedureReturn ret
    EndProcedure
    
    
    
    "Rain Cloud", "Cloud Storage"
    
    
    NewIcon( RainCloud (file$, img.i, size.i, #CSS_AliceBlue, #CSS_Silver))
    NewIcon( CloudStorage (file$, img.i, size.i, #CSS_AliceBlue, #CSS_Blue))
    
    
    NewIcon( RainCloud (file$, img.i, size.i, #CSS_WhiteSmoke, #CSS_Silver))
    NewIcon( CloudStorage (file$, img.i, size.i, #CSS_Silver, #CSS_DarkGrey))
    
    
DE AA EB
Post Reply