Page 1 of 18

Create your own icons for toolbars etc. with PureBasic

Posted: Sat Mar 05, 2016 8:03 pm
by Little John
For a project, I needed toolbar icons, and I didn't like what I found in free icon collections on the internet.
So I created myself scalable icons with the help of PureBasic's new vector library.

Contributions by other forum members are greatly appreciated.
Please use an existing icon procedure in the most recent version of the module as template for your icons,
or use the included program "newicon.pb" in order to get started.
Your code must be cross-platform, and must comply with the current final PureBasic version.
The main shape of an icon should be visible even at a size as small as 16x16 pixels.
Your code can only be included in this library, if you agree to its license (see below).

vectoricons.pbi wrote:

Code: Select all

; PB 5.40+, cross-platform
; Established and maintained by Little John, last updated on 2019-04-10
; http://www.purebasic.fr/english/viewtopic.php?f=12&t=65091


; TABLE OF CONTENTS OF THIS FILE
;===============================
; A) Utility module "VDraw"
;    - Procedure Color_Darken():
;      Darken a given RGBA color (the alpha channel is not changed)
;
;    - Procedure Color_Transparency():
;      Change the transparency of a given RGBA color
;
;    - Procedure StartNewVectorImage():
;      Wrapper for simplifying the usage of StartVectorDrawing() in
;      combination with CreateImage()
;
;  +----------------------------------------------------------------+
;  | CompilerIf #PB_Compiler_Version <= 542                          |
;  |    Macro AddPathArc():                                         |
;  |    Replacement for the built-in command AddPathArc(), which is |
;  |    buggy at least in PB 5.42 on Windows and Linux.             |
;  | CompilerEndIf                                                  |
;  +----------------------------------------------------------------+
;
; B) Main module "VectorIcons"
;    1) Public part
;       - CSS color definitions
;       - Own definitions of colors used in this module
;       * Declarations of public icon procedures
;
;    2) Private part
;       - Private constants
;       - Auxiliary procedures
;       - Private macros/procedures of basic movable and resizable shapes
;         that can be used by any icon procedure.
;       * Procedures which generate the icons, sometimes with an optional
;         parameter e.g. for flipping or rotating the respective icon.
License for 'VectorIcons' wrote:Copyright (c) 2016-2019 Jürgen Lüthje, Oma, davido, Guillaume Saumure,
infratec, and Romerio Medeiros
<viewtopic.php?f=12&t=65091>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, and/or sublicense the
Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

1) The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software, and in all products that
contain icons in any form which were produced by this software.

2) It is allowed to use the Software and/or icons produced by the Software in
non-commercial and commercial programs. However, commercial programs or
software collections MUST NOT contain the source code of the Software.

3) The restriction imposed by the second sentence of the previous paragraph
does not apply to any code in this project that was created by davido, or
infratec.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Most recent changes

2019-04-10
Changed
  • I've added an optional parameter to davido's nice Filter() procedure, which allows to draw only the outline of the filter.
  • minor cosmetic changes
New
  • written license! :-)
  • small program "newicon.pb", that could/should help creating your own vector icons

Here is the current collection (211+106+35 = 352 icons). Some procedures have optional parameters e.g. for rotating or flipping the generated icons, the following preview does not show all possible results. (The colors can be changed very easily.)

The icons in the first set were created by davido, Oma, StarBootics, infratec and me -- sometimes influenced by ideas of other forum members.

"Transparent", "Add", "Refresh", "SelectAll", "Checked", "Sub", "Delete", "Find",
"FindNext", "Question1", "Question2", "FivePointedStar", "Wizard", "Diskette",
"Alarm1", "Alarm2", "Quit", "HotDrink/Pause", "Watch", "Night", "UpArrow",
"DownArrow", "LeftArrow", "RightArrow", "ReSize", "Stop1", "Stop2", "Warning1",
"Warning2", "On", "Off", "Info1", "Info2", "Collapse", "Expand", "Success", "Home",
"AlignLeft", "AlignCentre", "AlignRight", "AlignJustify", "Compile", "CompileRun",
"Settings", "Options", "Toggle1", "Toggle2", "Save1", "ZoomIn", "ZoomOut",
"Great/OK", "Download1", "Upload1", "LineWrapOn", "LineWrapOff", "Donate1",
"Donate2", "Filter", "Bookmark", "Database", "Tools", "Sort", "Randomise",
"IsProtected", "UnProtected1", "UnProtected2", "Network", "Music", "Microphone",
"Picture", "Bug", "Debug", "Crop", "ReSize2", "Rating", "Orange Fruit",
"Lemon Fruit", "Lime Fruit", "Action", "Move", "Lock" , "Unlock", "Fill", "Message",
"Colours", "Navigation 1", "Navigation 2", "Volume", "Secure", "Book", "Library",
"USB", "Chess_WhitePawn", "Chess_BlackPawn", "Chess_WhiteRook", "Chess_BlackRook",
"Chess_WhiteKnight", "Chess_BlackKnight", "Chess_WhiteBishop", "Chess_BlackBishop",
"Chess_WhiteKing", "Chess_BlackKing", "Chess_WhiteQueen", "Chess_BlackQueen",
"History", "Danger", "The Sun", "Good Luck", "Telephone", "BlueTooth", "Broadcast",
"Speaker", "Mute", "Battery Charging", "Snowflake", "A2M", "N2Z", "Rain Cloud",
"Cloud Storage", "MediaPlay", "MediaStop", "MediaBegin", "MediaEnd", "MediaForward",
"MediaFastForward", "MediaBack", "MediaFastBack", "FirstAid", "NoEntry", "Stop3",
"Download2", "FirstAidSpatial", "NoEntrySpatial", "Stop3Spatial", "Download2Spatial",
"ToClipboard", "FromClipboard", "Copy", "Paste", "Cut", "Undo", "Redo", "Open1",
"Open2", "Open3", "Save2", "SaveAs2", "Printer1", "PrinterError1", "NewDocument",
"EditDocument", "ClearDocument", "ImportDocument", "ExportDocument", "CloseDocument",
"SortAscending", "SortDescending", "SortBlockAsc", "SortBlockDesc", "ChartLine",
"ChartDot", "ChartLineDot", "ChartPrice", "ChartBarVert", "ChartCylVert",
"ChartBarHor", "ChartCylHor", "ChartBarVertStacked", "ChartBarHorStacked",
"ChartCylVertStacked", "ChartCylHorStacked", "ChartArea", "ChartAreaPerc",
"ChartPie", "ChartRing", "Notes", "NotesSpatial", "UnfoldDown", "UnfoldUp/Eject",
"UnfoldLeft", "UnfoldRight", "FoldDown", "FoldUp", "FoldLeft", "FoldRight",
"ArrowBowTop2Right", "ArrowBowRight2Bottom", "ArrowBowBottom2Left",
"ArrowBowLeft2Top", "ArrowBowBottom2Right", "ArrowBowRight2Top", "ArrowBowTop2Left",
"ArrowBowLeft2Bottom", "BracketRoundOpen", "BracketRoundClose", "BracketSquareOpen",
"BracketSquareClose", "BracketAngleOpen", "BracketAngleClose", "BracketCurlyOpen",
"BracketCurlyClose", "BracketHtml", "Site", "Compare", "Attach", "Mail", "Currency",
"CurrencyEuro", "CurrencyDollar", "CurrencyPound", "CurrencyYen"


Image


All icons in the second set were created by Oma:

"FindAndReplace", "Open1Spatial", "Open2Spatial", "Open3Spatial", "FindFileSpatial",
"FindFile", "RotateDownSpatial", "RotateUpSpatial", "RotateVerticalSpatial",
"RotateLeftSpatial", "RotateRightSpatial", "RotateHorizontalSpatial",
"RotateCounterClockwiseSpatial", "RotateClockwiseSpatial", "WritingPad",
"WritingPadSpatial", "CalculateSpatial", "CalendarSpatial", "RulerSpatial",
"RulerTriangleSpatial", "CartonSpatial", "BookKeepingSpatial", "PenSpatial",
"PenFlat", "BrushSpatial", "BrushFlat", "PipetteSpatial", "PipetteFlat",
"FillSpatial", "FillFlat", "SpraySpatial", "SprayFlat", "EraserSpatial",
"EraserFlat", "ColorPaletteSpatial", "ColorPaletteFlat", "PaintSpatial", "PaintFlat",
"DrawVText", "DrawVLine", "DrawVBox", "DrawVRoundedBox", "DrawVPolygonBox",
"DrawVCircle", "DrawVCircleSegment", "DrawVEllipse", "DrawVEllipseSegment",
"DrawVCurve(Spline)", "DrawVArc", "DrawVLinePath", "SetVSelectRange",
"SetVLineStyle", "SetVLineWidth", "SetVLineCap", "SetVLineJoin", "SetVColorSelect",
"SetVColorBoardSelect", "SetVFlipX", "SetVFlipY", "SetVRotate", "SetVMove",
"SetVCopy", "SetVScale", "SetVTrimSegment", "SetVExtendSegment", "SetVCatchGrid",
"SetVLinearGradient", "SetVCircularGradient", "SetVChangeCoord", "SetVDelete",
"SetVFill", "SetVLayer", "ToClipboardSpatial", "FromClipboardSpatial", "CopySpatial",
"PasteSpatial", "CutSpatial", "FindSpatial", "FindNextSpatial",
"FindAndReplaceSpatial", "ZoomInSpatial", "ZoomOutSpatial", "NewDocument1Spatial",
"EditDocument1Spatial", "ClearDocument1Spatial", "ImportDocument1Spatial",
"ExportDocument1Spatial", "SaveDocument1Spatial", "CloseDocument1Spatial",
"SortAscending1Spatial", "SortDescending1Spatial", "SortBlockAscending1Spatial",
"SortBlockDescending1Spatial", "NewDocument2Spatial", "EditDocument2Spatial",
"ClearDocument2Spatial", "ImportDocument2Spatial", "ExportDocument2Spatial",
"SaveDocument2Spatial", "CloseDocument2Spatial", "SortAscending2Spatial",
"SortDescending2Spatial", "SortBlockAscending2Spatial",
"SortBlockDescending2Spatial", "SiteSpatial", "CompareSpatial"


Image


The icons in the third set were created by Oma, holzhacker, and me:

"Flag_Australia", "Flag_Austria", "Flag_Bangladesh", "Flag_Belgium", "Flag_Brazil",
"Flag_Bulgaria", "Flag_Canada", "Flag_China", "Flag_Czech", "Flag_Denmark",
"Flag_Estonia", "Flag_Europe", "Flag_Finland", "Flag_France", "Flag_Germany",
"Flag_GreatBritain", "Flag_Greece", "Flag_Hungary", "Flag_Ireland", "Flag_Island",
"Flag_Italy", "Flag_Japan", "Flag_SouthKorea", "Flag_Luxembourg", "Flag_Netherlands",
"Flag_NewZealand", "Flag_Norway", "Flag_Poland", "Flag_Romania", "Flag_Russia",
"Flag_Spain", "Flag_Sweden", "Flag_Switzerland", "Flag_Ukraine", "Flag_USA"


Image


Using the icons
On principle, there are 2 ways to use the icons:

a) Launch the included program "vectoriconbrowser.pb", and save icons as individual PNG files. Then use these files as shown in the example code "ToolBar.pb" that ships with PureBasic.

b) If you don't want to generate any icon files, you can also create the vector icons dynamically like so (this example is also included in the ZIP archive):

Code: Select all

; ------------------------------------------------------------
;
;   modified after
;   ToolBar example that ships with PureBasic;
;   tested with PB 5.44 LTS
;
; ------------------------------------------------------------

EnableExplicit

XIncludeFile "../vectoricons.pbi"

Enumeration
   #New
   #Open
   #Save
   #Find
EndEnumeration

Dim name$(#PB_Compiler_EnumerationValue-1)
name$(#New)  = "New"
name$(#Open) = "Open"
name$(#Save) = "Save"
name$(#Find) = "Find"


Define.i event, tbIconSize=16

If OpenWindow(0, 100, 200, 300, 250, "Vectoricons toolbar example", #PB_Window_SystemMenu | #PB_Window_SizeGadget) = 0
   MessageRequester("Fatal error", "Can't open main window.")
   End   
EndIf

If CreateToolBar(0, WindowID(0))
   ToolBarImageButton(#New, ImageID(VectorIcons::NewDocument("", #PB_Any, tbIconSize, 
                            VectorIcons::#CSS_White, VectorIcons::#CSS_Navy, VectorIcons::#CSS_Black)))
   ToolBarToolTip(0, #New, name$(#New))
   
   ToolBarImageButton(#Open, ImageID(VectorIcons::Open2("", #PB_Any, tbIconSize, 
                             VectorIcons::#CSS_GoldenRod, VectorIcons::#CSS_Navy, VectorIcons::#CSS_White)))
   ToolBarToolTip(0, #Open, name$(#Open))
   
   ToolBarImageButton(#Save, ImageID(VectorIcons::Diskette("", #PB_Any, tbIconSize, 
                             VectorIcons::#CSS_Navy, VectorIcons::#VI_GuardsmanRed, VectorIcons::#CSS_White)))
   ToolBarToolTip(0, #Save, name$(#Save))
   
   ToolBarSeparator()
   
   ToolBarImageButton(#Find, ImageID(VectorIcons::Find("", #PB_Any, tbIconSize, 
                             VectorIcons::#CSS_Black)))
   ToolBarToolTip(0, #Find, name$(#Find))
EndIf

If CreateMenu(0, WindowID(0))
   MenuTitle("Project")
   MenuItem(#New, name$(#New))
   MenuItem(#Open, name$(#Open))
   MenuItem(#Save, name$(#Save))
   
   MenuBar()
   
   MenuItem(#Find, name$(#Find))
EndIf

Repeat
   event = WaitWindowEvent()
   
   Select event
      Case #PB_Event_Menu
         MessageRequester("Information", "ToolBar or Menu ID: " + Str(EventMenu()))
   EndSelect
Until event = #PB_Event_CloseWindow    ; If the user has clicked on the close button
Download the ZIP archive with complete source code, and with all above icons as individual SVG files.

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

Posted: Sat Mar 05, 2016 8:08 pm
by RSBasic
Great Image

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

Posted: Sat Mar 05, 2016 8:14 pm
by Keya
nice! how many bytes of code in each icon? :)

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

Posted: Sat Mar 05, 2016 8:37 pm
by ts-soft
thanks, :D

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

Posted: Sat Mar 05, 2016 9:34 pm
by Andre
Very good, thank you! :D

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

Posted: Sat Mar 05, 2016 10:07 pm
by davido
Very useful.
Works fine on my MacBook.
Thank you, very much for sharing.

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

Posted: Sat Mar 05, 2016 10:19 pm
by Demivec
Keya wrote:nice! how many bytes of code in each icon? :)
According to GetFunSize():
Windows x64 Sizes
---------------------------
Icon_Add(): 61 bytes
Icon_Delete(): 59 bytes
Icon_Refresh(): 76 bytes
Icon_SelectAll(): 99 bytes

Windows x86 Sizes
---------------------------
Icon_Add(): 47
Icon_Delete(): 36
Icon_Refresh(): 62
Icon_SelectAll(): 53
All sizes are less than 1/5 the file size for their corresponding png file.

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

Posted: Sun Mar 06, 2016 10:00 am
by VB6_to_PBx
great idea !!! 8) :idea:
thanks

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

Posted: Sun Mar 06, 2016 11:22 am
by Keya
Demivec wrote:
Keya wrote:nice! how many bytes of code in each icon? :)
According to GetFunSize():
Windows x64 Sizes
---------------------------
Icon_Add(): 61 bytes
Icon_Delete(): 59 bytes
Icon_Refresh(): 76 bytes
Icon_SelectAll(): 99 bytes

Windows x86 Sizes
---------------------------
Icon_Add(): 47
Icon_Delete(): 36
Icon_Refresh(): 62
Icon_SelectAll(): 53
All sizes are less than 1/5 the file size for their corresponding png file.
That only calculates the size of a single function; it doesn't include the size of any CALL'd supporting functions for example

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

Posted: Sun Mar 06, 2016 11:47 am
by Little John
Thanks to all for your positive feedback.
davido wrote:Works fine on my MacBook.
I can't test myself on a Mac, so thank you for mentioning that.

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

Posted: Tue Mar 08, 2016 8:46 pm
by StarBootics
Hello everyone,

For those you need a subtract icon :

Code: Select all

Procedure.i Icon_Sub(img.i, size.i, color.i)
  ; in : img  : number of the image which is to be created, or #PB_Any
  ;      size : number of pixels (width and height)
  ;      color: foreground color of the image (background is transparent)
  ; out: return value: if img = #Pb_Any => number of the created image,
  ;                    error => 0
  Protected ret.i, hi.i, lo.i
  
  hi = 2 * Int(size / 3)
  lo = size - hi
  
  ret = CreateImage(img, size, size, 32, #PB_Image_Transparent)
  If img = #PB_Any
    img = ret
  EndIf
  
  If ret And StartVectorDrawing(ImageVectorOutput(img))
    VectorSourceColor(color)
    
    MovePathCursor( 0, lo)
    AddPathLine   (size, lo)
    AddPathLine   (size, hi)
    AddPathLine   (lo, hi)
    AddPathLine   ( 0, hi)
    ClosePath()
    FillPath()
    
    StopVectorDrawing()
  EndIf
  
  ProcedureReturn ret
EndProcedure
Notes : This is a derivate from the "Add" Icon, so I deserve no credit for this code.

Best regards
StarBootics

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

Posted: Wed Mar 09, 2016 7:27 am
by HanPBF
Hello Little John, thanks a lot for this great demonstration!

It seems to me meanwhile the vector drawing library is really smart...

This great library makes Googles material design easy to manage (https://www.google.com/design/spec/mate ... ction.html)

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

Posted: Wed Mar 09, 2016 9:55 am
by Little John
StarBootics wrote:For those you need a subtract icon :
Hi,

when I saw the code for the "Subtract" icon, my first thought was: This can be done simpler just by drawing a line.
Then it became clear to me that the "Add" icon can be done simpler as well, just by drawing two lines. :-)
I've changed the code in the first post accordingly.

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

Posted: Wed Mar 09, 2016 8:29 pm
by StarBootics
What about a Module containing a fully set of Icons ?

Code: Select all

DeclareModule VectorIcons
  
  Declare Add(img.i, size.i, color.i)
  Declare Sub(img.i, size.i, color.i)
  Declare Refresh(img.i, size.i, color.i)
  Declare SelectAll(img.i, size.i, color.i)
  Declare Delete(img.i, size.i, color.i)
  
  Declare UpArrow(img.i, size.i, color.i)
  Declare RightArrow(img.i, size.i, color.i)
  Declare LeftArrow(img.i, size.i, color.i)
  Declare DownArrow(img.i, size.i, color.i)
  
  ; Declare Interrogation(img.i, size.i, color.i)
  ; Declare Exclamation(img.i, size.i, color.i)
  
EndDeclareModule

Module VectorIcons
  
  Procedure.i Add(img.i, size.i, color.i)
    ; in : img  : number of the image which is to be created, or #PB_Any
    ;      size : number of pixels (width and height)
    ;      color: foreground color of the image (background is transparent)
    ; out: return value: if img = #Pb_Any => number of the created image,
    ;                    error => 0
    Protected ret.i, w.i, half.d
    
    w = Int(size / 3.0) - (size % 3)
    half = size / 2.0
    
    ret = CreateImage(img, size, size, 32, #PB_Image_Transparent)
    If img = #PB_Any
      img = ret
    EndIf
    
    If ret And StartVectorDrawing(ImageVectorOutput(img))
      VectorSourceColor(color)
      
      MovePathCursor(   0, half)
      AddPathLine   (size, half)
      MovePathCursor(half,    0)
      AddPathLine   (half, size)
      StrokePath(w)
      
      StopVectorDrawing()
    EndIf
    
    ProcedureReturn ret
  EndProcedure
  
  Procedure.i Sub(img.i, size.i, color.i)
    ; in : img  : number of the image which is to be created, or #PB_Any
    ;      size : number of pixels (width and height)
    ;      color: foreground color of the image (background is transparent)
    ; out: return value: if img = #Pb_Any => number of the created image,
    ;                    error => 0
    Protected ret.i, w.i, half.d
    
    w = Int(size / 3.0) - (size % 3)
    half = size / 2.0
    
    ret = CreateImage(img, size, size, 32, #PB_Image_Transparent)
    If img = #PB_Any
      img = ret
    EndIf
    
    If ret And StartVectorDrawing(ImageVectorOutput(img))
      VectorSourceColor(color)
      MovePathCursor(   0, half)
      AddPathLine   (size, half)
      MovePathCursor(half,    0)
      StrokePath(w)
      StopVectorDrawing()
    EndIf
    
    ProcedureReturn ret
  EndProcedure
  
  Macro ArrowRefresh()
    MovePathCursor(hw, half-hw)
    AddPathCurve(third, hw, size-third, hw, size-1.75*hw, half-2.0*hw)
    StrokePath(2.0 * hw)
    
    MovePathCursor(         size, half-hw)
    AddPathLine   (size-hw-third, half-0.5*hw)
    AddPathLine   (  size-1.5*hw, 0)
    ClosePath()
    FillPath()
  EndMacro
  
  Procedure.i Refresh(img.i, size.i, color.i)
    ; in : img  : number of the image which is to be created, or #PB_Any
    ;      size : number of pixels (width and height)
    ;      color: foreground color of the image (background is transparent)
    ; out: return value: if img = #Pb_Any => number of the created image,
    ;                    error => 0
    Protected ret.i, hw.d, half.d, third.d
    
    hw = size / 12.0
    half = size / 2.0
    third = size / 3.0
    
    ret = CreateImage(img, size, size, 32, #PB_Image_Transparent)
    If img = #PB_Any
      img = ret
    EndIf
    
    If ret And StartVectorDrawing(ImageVectorOutput(img))
      VectorSourceColor(color)
      
      ArrowRefresh()     ; upper arrow
      RotateCoordinates(half, half, 180.0)
      ArrowRefresh()     ; lower arrow
      
      StopVectorDrawing()
    EndIf
    
    ProcedureReturn ret
  EndProcedure
  
  
  Procedure.i SelectAll(img.i, size.i, color.i)
    ; in : img  : number of the image which is to be created, or #PB_Any
    ;      size : number of pixels (width and height)
    ;      color: foreground color of the image (background is transparent)
    ; out: return value: if img = #Pb_Any => number of the created image,
    ;                    error => 0
    Protected ret.i, hw.d
    Protected Dim dash.d(1)
    
    hw = size / 16.0
    
    ret = CreateImage(img, size, size, 32, #PB_Image_Transparent)
    If img = #PB_Any
      img = ret
    EndIf
    
    If ret And StartVectorDrawing(ImageVectorOutput(img))
      VectorSourceColor(color)
      
      MovePathCursor(      0, hw)      : AddPathLine(size, hw)
      MovePathCursor(size-hw, 0)       : AddPathLine(size-hw, size)
      MovePathCursor(      0, size-hw) : AddPathLine(size, size-hw)
      MovePathCursor(     hw, 0)       : AddPathLine(hw, size)
      dash(1) = size / 11.0
      dash(0) = 2.0 * dash(1)
      CustomDashPath(2.0 * hw, dash())
      
      AddPathBox(5.0*hw, 5.0*hw, 6.0*hw, 6.0*hw)
      StrokePath(2.0 * hw)
      
      StopVectorDrawing()
    EndIf
    
    ProcedureReturn ret
  EndProcedure
  
  
  Procedure.i Delete(img.i, size.i, color.i)
    ; in : img  : number of the image which is to be created, or #PB_Any
    ;      size : number of pixels (width and height)
    ;      color: foreground color of the image (background is transparent)
    ; out: return value: if img = #Pb_Any => number of the created image,
    ;                    error => 0
    Protected.i ret.i, hw.d, d.d
    
    hw = size / 14.0
    d = size / 10.0
    
    ret = CreateImage(img, size, size, 32, #PB_Image_Transparent)
    If img = #PB_Any
      img = ret
    EndIf
    
    If ret And StartVectorDrawing(ImageVectorOutput(img))
      VectorSourceColor(color)
      
      MovePathCursor(     hw, hw+d)
      AddPathLine   (size-hw, size-hw)
      AddPathLine   (   hw+d, hw)
      ClosePath()
      MovePathCursor(  3.0*hw, size-hw-d)
      AddPathLine   ( size-hw, 3.0*hw)
      AddPathLine   (3.0*hw+d, size-hw)
      ClosePath()
      StrokePath(2.0 * hw, #PB_Path_RoundCorner)
      
      StopVectorDrawing()
    EndIf
    
    ProcedureReturn ret
  EndProcedure
  
  Macro DrawUpArrow()
    
    MovePathCursor(half, 0)
    AddPathLine   (x1, y1)
    AddPathLine   (x2, y1)
    ClosePath()
    FillPath()
    MovePathCursor(half, y1)
    AddPathLine   (half, size)
    StrokePath(w)
    
  EndMacro
  
  Procedure UpArrow(img.i, size.i, color.i)
    
    ; in : img  : number of the image which is to be created, or #PB_Any
    ;      size : number of pixels (width and height)
    ;      color: foreground color of the image (background is transparent)
    ; out: return value: if img = #Pb_Any => number of the created image,
    ;                    error => 0
    Protected ret.i, w.i, half.d, x1.d, y1.d, x2.d
    
    w = Int(size / 3.0) - (size % 3)
    half = size / 2.0
    x1 = half - size / 2.5
    y1 = 3.5 * size / 8.0
    x2 = half + size / 2.5
    
    ret = CreateImage(img, size, size, 32, #PB_Image_Transparent)
    If img = #PB_Any
      img = ret
    EndIf
    
    If ret And StartVectorDrawing(ImageVectorOutput(img))
      
      VectorSourceColor(color)
      DrawUpArrow()
      
      StopVectorDrawing()
    EndIf
    
    ProcedureReturn ret
  EndProcedure
  
  Procedure DownArrow(img.i, size.i, color.i)
    
    ; in : img  : number of the image which is to be created, or #PB_Any
    ;      size : number of pixels (width and height)
    ;      color: foreground color of the image (background is transparent)
    ; out: return value: if img = #Pb_Any => number of the created image,
    ;                    error => 0
    Protected ret.i, w.i, half.d, x1.d, y1.d, x2.d
    
    w = Int(size / 3.0) - (size % 3)
    half = size / 2.0
    x1 = half - size / 2.5
    y1 = 3.5 * size / 8.0
    x2 = half + size / 2.5
    
    ret = CreateImage(img, size, size, 32, #PB_Image_Transparent)
    If img = #PB_Any
      img = ret
    EndIf
    
    If ret And StartVectorDrawing(ImageVectorOutput(img))
      
      VectorSourceColor(color)
      RotateCoordinates(half, half, 180.0)
      DrawUpArrow()
      
      StopVectorDrawing()
    EndIf
    
    ProcedureReturn ret
  EndProcedure
  
  
    Procedure LeftArrow(img.i, size.i, color.i)
    
    ; in : img  : number of the image which is to be created, or #PB_Any
    ;      size : number of pixels (width and height)
    ;      color: foreground color of the image (background is transparent)
    ; out: return value: if img = #Pb_Any => number of the created image,
    ;                    error => 0
    Protected ret.i, w.i, half.d, x1.d, y1.d, x2.d
    
    w = Int(size / 3.0) - (size % 3)
    half = size / 2.0
    x1 = half - size / 2.5
    y1 = 3.5 * size / 8.0
    x2 = half + size / 2.5
    
    ret = CreateImage(img, size, size, 32, #PB_Image_Transparent)
    If img = #PB_Any
      img = ret
    EndIf
    
    If ret And StartVectorDrawing(ImageVectorOutput(img))
      
      VectorSourceColor(color)
      RotateCoordinates(half, half, -90.0)
      DrawUpArrow()
      
      StopVectorDrawing()
    EndIf
    
    ProcedureReturn ret
  EndProcedure
  
    Procedure RightArrow(img.i, size.i, color.i)
    
    ; in : img  : number of the image which is to be created, or #PB_Any
    ;      size : number of pixels (width and height)
    ;      color: foreground color of the image (background is transparent)
    ; out: return value: if img = #Pb_Any => number of the created image,
    ;                    error => 0
    Protected ret.i, w.i, half.d, x1.d, y1.d, x2.d
    
    w = Int(size / 3.0) - (size % 3)
    half = size / 2.0
    x1 = half - size / 2.5
    y1 = 3.5 * size / 8.0
    x2 = half + size / 2.5
    
    ret = CreateImage(img, size, size, 32, #PB_Image_Transparent)
    If img = #PB_Any
      img = ret
    EndIf
    
    If ret And StartVectorDrawing(ImageVectorOutput(img))
      
      VectorSourceColor(color)
      RotateCoordinates(half, half, 90.0)
      DrawUpArrow()
      
      StopVectorDrawing()
    EndIf
    
    ProcedureReturn ret
  EndProcedure
  
  
  
  
  
  
  
EndModule

CompilerIf #PB_Compiler_IsMainFile
  
  Enumeration
    #ImgAdd
    #ImgSub
    #ImgRefresh
    
    #ImgSelectAll
    #ImgDelete
    #ImgUp
    
    #ImgDown
    #ImgLeft
    #ImgRight
    
    #ImgAdd_d
    #ImgSub_d
    #ImgRefresh_d
    #ImgSelectAll_d
    #ImgDelete_d
    #ImgUp_d
    #ImgDown_d    
    #ImgLeft_d
    #ImgRight_d
    
  EndEnumeration
  
  
  Define.i i, btnSave, btnExit, green, red, grey, size, icons=9
  Define dir$
  
  ; --------------------------------
  size = 32
  dir$ = GetTemporaryDirectory()      ; whee to save the image files
                                      ; --------------------------------
  
  green = RGBA(0, 128, 0, 255)
  red   = RGBA(192, 0, 0, 255)
  grey  = RGBA(192, 192, 192, 255)
  
  VectorIcons::Add(#ImgAdd, size, green)
  VectorIcons::Sub(#ImgSub, size, green)
  VectorIcons::Refresh(#ImgRefresh, size, green)
  VectorIcons::SelectAll(#ImgSelectAll, size, green)
  VectorIcons::Delete(#ImgDelete, size, red)
  
  VectorIcons::UpArrow(#ImgUp, size, green)
  VectorIcons::DownArrow(#ImgDown, size, green)
  VectorIcons::LeftArrow(#ImgLeft, size, green)
  VectorIcons::RightArrow(#ImgRight, size, green)
  
  VectorIcons::Add(#ImgAdd_d, size, grey)
  VectorIcons::Sub(#ImgSub_d, size, grey)
  VectorIcons::Refresh(#ImgRefresh_d, size, grey)
  VectorIcons::SelectAll(#ImgSelectAll_d, size, grey)
  VectorIcons::Delete(#ImgDelete_d, size, grey)
  
  VectorIcons::UpArrow(#ImgUp_d, size, grey)
  VectorIcons::DownArrow(#ImgDown_d, size, grey)
  VectorIcons::LeftArrow(#ImgLeft_d, size, grey)
  VectorIcons::RightArrow(#ImgRight_d, size, grey)
  
  
  OpenWindow(0, 0, 0, icons*(size+25), 2*size+150, "Icons", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  For i = 0 To icons-1
    ImageGadget(#PB_Any, 10+i*(size+20), 10, size, size, ImageID(i))
  Next
  
  For i = icons To 2*icons-1
    ImageGadget(#PB_Any, 10+(i-icons)*(size+20), 40+size, size, size, ImageID(i))
  Next
  
  btnSave = ButtonGadget(#PB_Any, WindowWidth(0)-140, WindowHeight(0)-40, 60, 30, "Save")
  btnExit = ButtonGadget(#PB_Any, WindowWidth(0)- 70, WindowHeight(0)-40, 60, 30, "Exit")
  
  UsePNGImageEncoder()
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case btnSave
            SaveImage(#ImgAdd,       dir$ + "Add.png", #PB_ImagePlugin_PNG)
            SaveImage(#ImgRefresh,   dir$ + "Refresh.png", #PB_ImagePlugin_PNG)
            SaveImage(#ImgSelectAll, dir$ + "SelectAll.png", #PB_ImagePlugin_PNG)
            SaveImage(#ImgDelete,    dir$ + "Delete.png", #PB_ImagePlugin_PNG)
            
            SaveImage(#ImgAdd_d,       dir$ + "Add_d.png", #PB_ImagePlugin_PNG)
            SaveImage(#ImgRefresh_d,   dir$ + "Refresh_d.png", #PB_ImagePlugin_PNG)
            SaveImage(#ImgSelectAll_d, dir$ + "SelectAll_d.png", #PB_ImagePlugin_PNG)
            SaveImage(#ImgDelete_d,    dir$ + "Delete_d.png", #PB_ImagePlugin_PNG)
            
            MessageRequester("Save", "Done.")
            
          Case btnExit
            Break
        EndSelect
        
      Case #PB_Event_CloseWindow
        Break
    EndSelect
  ForEver
  
CompilerEndIf
Best regards
StarBootics

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

Posted: Wed Mar 09, 2016 9:16 pm
by Little John
Nice!
I would really like the collection to grow over time.