It is currently Thu Nov 23, 2017 12:08 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 240 posts ]  Go to page 1, 2, 3, 4, 5 ... 16  Next
Author Message
 Post subject: Create your own icons for toolbars etc. with PureBasic
PostPosted: Sat Mar 05, 2016 8:03 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3142
Location: Berlin, Germany
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.
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.


vectoricons.pbi wrote:
Code:
; PB 5.40+, cross-platform
; established and maintained by Little John, 2017-03-17
; 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.

Most recent changes:
2017-08-27
New great stuff from Oma (1st icon set):
  • 30 flags
  • 7 other icons
  • several new color definitions

Here is the current collection (241+106 = 347 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",
"FlagAustralia", "FlagAustria", "FlagBelgium", "FlagBulgaria", "FlagCanada", "FlagChina",
"FlagSouthCorea", "FlagCzech", "FlagDenmark", "FlagFinland", "FlagFrance", "FlagGermany",
"FlagGreatBritain", "FlagGreece", "FlagHungary", "FlagIreland", "FlagIsland", "FlagItaly",
"FlagJapan", "FlagLuxembourg", "FlagNetherlands", "FlagNewZealand", "FlagNorway", "FlagPoland",
"FlagRomania", "FlagRussia", "FlagSweden", "FlagSwitzerland", "FlagUSA", "FlagUkraine"


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


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:
; ------------------------------------------------------------
;
;   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.

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Last edited by Little John on Sun Aug 27, 2017 12:32 pm, edited 86 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Create your own icons for toolbars etc. with PureBasic
PostPosted: Sat Mar 05, 2016 8:08 pm 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 377
Location: Berlin and Ibiza
Great Image

_________________
ImageImageImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: Create your own icons for toolbars etc. with PureBasic
PostPosted: Sat Mar 05, 2016 8:14 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 04, 2015 7:10 am
Posts: 1673
nice! how many bytes of code in each icon? :)

_________________
Thankyou to all the coders who generously helped & encouraged me in the nearly 2yrs when i was welcome here,
it was a tremendous privilege. I learned a lot. I wish you and your families all the best and success for the future.


Top
 Profile  
Reply with quote  
 Post subject: Re: Create your own icons for toolbars etc. with PureBasic
PostPosted: Sat Mar 05, 2016 8:37 pm 
Offline
Always Here
Always Here
User avatar

Joined: Thu Jun 24, 2004 2:44 pm
Posts: 5726
Location: Berlin - Germany
thanks, :D

_________________
PureBasic 5.61 | SpiderBasic 2.10 | Windows 10 Pro (x64) | Linux Mint 18.2 (x64)
I would like to change the world, but God does not release the source code.
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Create your own icons for toolbars etc. with PureBasic
PostPosted: Sat Mar 05, 2016 9:34 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 6:14 pm
Posts: 1391
Location: Germany (Saxony, Deutscheinsiedel)
Very good, thank you! :D

_________________
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)


Top
 Profile  
Reply with quote  
 Post subject: Re: Create your own icons for toolbars etc. with PureBasic
PostPosted: Sat Mar 05, 2016 10:07 pm 
Offline
Addict
Addict

Joined: Fri Nov 09, 2012 11:04 pm
Posts: 1461
Location: Uttoxeter, UK
Very useful.
Works fine on my MacBook.
Thank you, very much for sharing.

_________________
DE AA EB


Top
 Profile  
Reply with quote  
 Post subject: Re: Create your own icons for toolbars etc. with PureBasic
PostPosted: Sat Mar 05, 2016 10:19 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3423
Location: Utah, USA
Keya wrote:
nice! how many bytes of code in each icon? :)


According to GetFunSize():
Quote:
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.

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Create your own icons for toolbars etc. with PureBasic
PostPosted: Sun Mar 06, 2016 10:00 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon May 09, 2011 9:36 am
Posts: 346
great idea !!! 8) :idea:
thanks

_________________
 
PureBasic .... making little electrons do what you want !


Top
 Profile  
Reply with quote  
 Post subject: Re: Create your own icons for toolbars etc. with PureBasic
PostPosted: Sun Mar 06, 2016 11:22 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 04, 2015 7:10 am
Posts: 1673
Demivec wrote:
Keya wrote:
nice! how many bytes of code in each icon? :)


According to GetFunSize():
Quote:
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

_________________
Thankyou to all the coders who generously helped & encouraged me in the nearly 2yrs when i was welcome here,
it was a tremendous privilege. I learned a lot. I wish you and your families all the best and success for the future.


Top
 Profile  
Reply with quote  
 Post subject: Re: Create your own icons for toolbars etc. with PureBasic
PostPosted: Sun Mar 06, 2016 11:47 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3142
Location: Berlin, Germany
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.

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Create your own icons for toolbars etc. with PureBasic
PostPosted: Tue Mar 08, 2016 8:46 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jul 07, 2013 11:35 am
Posts: 311
Hello everyone,

For those you need a subtract icon :

Code:
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

_________________
The Stone Age did not end due to a shortage of stones !


Top
 Profile  
Reply with quote  
 Post subject: Re: Create your own icons for toolbars etc. with PureBasic
PostPosted: Wed Mar 09, 2016 7:27 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Feb 19, 2010 3:42 am
Posts: 417
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/material-design/introduction.html)


Top
 Profile  
Reply with quote  
 Post subject: Re: Create your own icons for toolbars etc. with PureBasic
PostPosted: Wed Mar 09, 2016 9:55 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3142
Location: Berlin, Germany
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.

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Create your own icons for toolbars etc. with PureBasic
PostPosted: Wed Mar 09, 2016 8:29 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Jul 07, 2013 11:35 am
Posts: 311
What about a Module containing a fully set of Icons ?

Code:
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

_________________
The Stone Age did not end due to a shortage of stones !


Top
 Profile  
Reply with quote  
 Post subject: Re: Create your own icons for toolbars etc. with PureBasic
PostPosted: Wed Mar 09, 2016 9:16 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3142
Location: Berlin, Germany
Nice!
I would really like the collection to grow over time.

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 240 posts ]  Go to page 1, 2, 3, 4, 5 ... 16  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 11 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye