Challenge: 
Winner?: 
No
Code Snippet: 
remstart
Paint program by
Sven B
remend

set display mode 1024, 768, 32
sync on : sync rate 0
color backdrop 0
backdrop off
disable escapekey

`This are the constants used for the layout
#constant Theme = RGB(189,6,56)
#constant ThemeBack = RGB(255,162,21)
#constant ThemeTxt = rgb(255, 255, 0)
#constant ThemeFont = "Comic Sans MS"

`Possible export extensions (taken from http://darkbasicpro.thegamecreators.com/?f=features)
dim Export$(4)
Export$(1) = ".bmp"
Export$(2) = ".jpg"
Export$(3) = ".dib"
Export$(4) = ".dds"

`Possible load extensions (taken from http://darkbasicpro.thegamecreators.com/?f=features)
dim Import$(6)
Import$(1) = ".bmp"
Import$(2) = ".dib"
Import$(3) = ".png"
Import$(4) = ".jpg"
Import$(5) = ".dds"
Import$(6) = ".tga"

`Initialize the paint program
gosub Initialize

`Create media
gosub CreateMedia

r = SBCreateWindow(100, 150, 200, 200, 150, 150)

do

   `Paste hud
   paste image GUI + 2, 0, 0

   `Handle buttons
   gosub Buttons

   `Handle windows
   gosub Windows

   `If zoom window is turned on, create a zoom right from this window
   if ZoomWind = 1
      CreateZoom(mousex(), mousey())
   else
      if sprite exist(ZoomImg) > 0 then delete sprite ZoomImg
      if sprite exist(ZoomImg + 1) > 0 then delete sprite ZoomImg + 1
   endif

   sync
loop

`********************************
`Subs
`********************************

Windows:

   `Handle all windows
   Windows = array count(Window(0))
   if Windows > 0
      for w = 1 to Windows
         HandleWindow(w)
      next w

      `If there is an active window
      if ActiveWindow > 0
         `Handle it
         HandleActiveWindow(ActiveWindow)
      else

         `Else, if the mouse is pressed, search for a new active window
         if mouseclick() > 0

            `Go off all windows
            for w = 1 to Windows
               if mousex() > Window(w).x and mousex() < Window(w).x + Window(w).sx
                  if mousey() > Window(w).y and mousey() < Window(w).y + Window(w).sy + 8
                     ActiveWindow = w
                  endif
               endif
            next w

         endif

      endif
   endif

return

Buttons:

   `New
   if mousex() > 1 and mousex() < 51 and mousey() < 50
      paste image GUI + 3, 1, 1

      `Create new
      if mouseclick() > 0
         gosub New
      endif

   endif

   `Load
   if mousex() > 51 and mousex() < 101 and mousey() < 50
      paste image GUI + 4, 51, 1
      if mouseclick() = 1 then gosub Load
   endif

   `Export
   if mousex() > 101 and mousex() < 151 and mousey() < 50
      paste image GUI + 5, 101, 1
      if mouseclick() = 1 then gosub Export
   endif

   `Exit
   if mousex() > 151 and mousex() < 201 and mousey() < 50
      paste image GUI + 6, 151, 1
      if mouseclick() = 1 then end
   endif

   `Tools
   `Pen tool
   if mousex() > scrX - 49 and mousex() < scrX - 25 and mousey() > 51 and mousey() < 74 or CTool = 1
      paste image GUI + 7, scrX - 49, 51
      if mouseclick() = 1 then CTool = 1
   endif

   `Circle tool
   if mousex() > scrX - 24 and mousey() > 51 and mousey() < 74 or CTool = 2
      paste image GUI + 8, scrX - 24, 51
      if mouseclick() = 1 then CTool = 2
   endif

   `Box tool
   if mousex() > scrX - 49 and mousex() < scrX - 24 and mousey() > 76 and mousey() < 99 or CTool = 3
      paste image GUI + 9, scrX - 49, 76
      if mouseclick() = 1 then CTool = 3
   endif

   `Fill tool
   if mousex() > scrX - 24 and mousey() > 76 and mousey() < 99 or CTool = 4
      paste image GUI + 10, scrX - 24, 76
      if mouseclick() = 1 then CTool = 4
   endif

   `Line tool
   if mousex() > scrX - 49 and mousex() < scrX - 25 and mousey() > 101 and mousey() < 124 or CTool = 5
      paste image GUI + 11, scrX - 49, 101
      if mouseclick() = 1 then CTool = 5
   endif

   `Zoom window
   if mousex() > scrX - 24 and mousey() > 101 and mousey() < 124
      paste image GUI + 12, scrX - 24, 101
      if mouseclick() = 1
         ZoomWind = abs(ZoomWind - 1)
         repeat : until mouseclick() = 0
      endif
   endif
   if ZoomWind = 1
      paste image GUI + 12, scrX - 24, 101
   endif

   `Spray tool
   if mousex() > scrX - 49 and mousex() < scrX - 26 and mousey() > 126 and mousey() < 149 or CTool = 6
      paste image GUI + 13, scrX - 49, 126
      if mouseclick() = 1 then CTool = 6
   endif

   `Display brush options when CTool = 7
   if CTool = 6

      `Increase/decrease radius
      ink ThemeTxt, 0
      text scrX - 48, 170, "Size"
      ToolSize = IncDecValue(scrX - 48, 194, ToolSize)

      `Increase/decrease radius
      ink ThemeTxt, 0
      text scrX - 48, 220, "Density"
      ToolDensity = IncDecValue(scrX - 48, 242, ToolDensity)

   endif

   `Brush tool
   if mousex() > scrX - 24 and mousey() > 126 and mousey() < 149 or CTool = 7
      paste image GUI + 14, scrX - 24, 126
      if mouseclick() = 1 then CTool = 7
   endif

   `RGB color
   `The red value
   if mousey() > scrY - 270 and mousey() < scrY - 5 and mouseclick() = 1
      if mousex() > scrX - 43 and mousex() < scrX - 36
         ForRed = scrY - mousey() - 10
         if ForRed < 0 then ForRed = 0
         if ForRed > 255 then ForRed = 255
      endif
      if mousex() > scrX - 29 and mousex() < scrX - 22
         ForGreen = scrY - mousey() - 10
         if ForGreen < 0 then ForGreen = 0
         if ForGreen > 255 then ForGreen = 255
      endif
      if mousex() > scrX - 15 and mousex() < scrX - 8
         ForBlue = scrY - mousey() - 10
         if ForBlue < 0 then ForBlue = 0
         if ForBlue > 255 then ForBlue = 255
      endif
   endif
   ForColor = rgb(ForRed, ForGreen, ForBlue)

   `Display boxes
   box scrX - 43, scrY - 10 - ForRed, scrX - 36, scrY - 10, rgb(255, 255, 255), rgb(255, 255, 255), rgb(255, 0, 0), rgb(255, 0, 0)
   box scrX - 29, scrY - 10 - ForGreen, scrX - 22, scrY - 10, rgb(255, 255, 255), rgb(255, 255, 255), rgb(0, 255, 0), rgb(0, 255, 0)
   box scrX - 15, scrY - 10 - ForBlue, scrX - 8, scrY - 10, rgb(255, 255, 255), rgb(255, 255, 255), rgb(0, 0, 255), rgb(0, 0, 255)

   `Main color
   ink ForColor, 0
   box scrX - 47, scrY - 305, scrX - 3, scrY - 271

   `Color picker
   if mouseclick() = 1 and mousex() > scrX - 47 and mousex() < scrX - 3
      if mousey() > scrY - 305 and mousey() < scrY - 271
         ActiveWindow = 0

         `Color picker
         size sprite GUI, 320, 8
         paste sprite GUI, 0, 0
         paste image GUI + 1, 313, 1
         ink Theme, 0
         box 0, 8, 320, 208
         ink ThemeBack, 0
         box 1, 8, 319, 207
         `Create color picker
         for i = 0 to 255 step 5
            box 5 + (i/5), 12, 6 + (i/5), 102, rgb(255, i, 0), rgb(255, 255, 255), rgb(255, i, 0), rgb(255, 255, 255)
            box 56 + (i/5), 12, 57 + (i/5), 102, rgb(255 - i, 255, 0), rgb(255, 255, 255), rgb(255 - i, 255, 0), rgb(255, 255, 255)
            box 107 + (i/5), 12, 108 + (i/5), 102, rgb(0, 255, i), rgb(255, 255, 255), rgb(0, 255, i), rgb(255, 255, 255)
            box 158 + (i/5), 12, 159 + (i/5), 102, rgb(0, 255 - i, 255), rgb(255, 255, 255), rgb(0, 255 - i, 255), rgb(255, 255, 255)
            box 209 + (i/5), 12, 210 + (i/5), 102, rgb(i, 0, 255), rgb(255, 255, 255), rgb(i, 0, 255), rgb(255, 255, 255)
            box 260 + (i/5), 12, 261 + (i/5), 102, rgb(255, 0, 255 - i), rgb(255, 255, 255), rgb(255, 0, 255 - i), rgb(255, 255, 255)
         next i
         box 5, 107, 311, 122, rgb(0, 0, 0), rgb(0, 0, 0), rgb(255, 255, 255), rgb(255, 255, 255)
         box 90, 156, 190, 176, Theme, rgb(255, 255, 255), Theme, rgb(255, 255, 255)
         get image Bin, 0, 0, 320, 208, 1
         make memblock from image Bin, Bin

         `Get X and Y window coords
         wx = (scrX/2) - 160
         wy = (scrY/2) - 104
         mx = wx + 5
         my = wy + 12
         tempRed = 255
         tempGreen = 255
         tempBlue = 255
         tempAlpha = 255

         do

            `Refresh
            paste image GUI + 2, 0, 0

            `Handle windows
            Windows = array count(Window(0))
            if Windows > 0
               for w = 1 to Windows
                  HandleWindow(w)
               next w
            endif

            `Display window
            paste image Bin, wx, wy

            `Clicking
            if mouseclick() > 0

               `Quit
               if mousex() > wx + 313 and mousex() < wx + 319
                  if mousey() > wy + 1 and mousey() < wy + 7
                     exit
                  endif
               endif

               `Color picking
               posx = mousex() - wx
               posy = mousey() - wy
               if posx >= 5 and posy >= 12
                  if posx <= 311 and posy < 102

                     mx = mousex() : my = mousey()

                     `Extract color
                     pos = 12 + (((posy*320) + posx)*4)
                     tempBlue = memblock byte(Bin, pos)
                     tempGreen = memblock byte(Bin, pos+1)
                     tempRed = memblock byte(Bin, pos + 2)

                  endif
               endif

               `Alpha
               if posx >= 5 and posx <= 311
                  if posy >= 107 and posy <= 122
                     tempAlpha = 255.0 / 306.0 * (posx - 5)
                  endif
               endif

            endif

            `Accept
            if mousex() > wx + 90 and mousex() < wx + 190
               if mousey() > wy + 156 and mousey() < wy + 176
                  box wx + 90, wy + 156, wx + 190, wy + 176, rgb(255, 255, 255), Theme, rgb(255, 255, 255), Theme
                  if mouseclick() = 1
                     ForRed = tempRed / 255.0 * tempAlpha
                     ForGreen = tempGreen / 255.0 * tempAlpha
                     ForBlue = tempBlue / 255.0 * tempAlpha
                     exit
                  endif
               endif
            endif
            ink ThemeTxt, 0
            center text wx + 140, wy + 157, "Change"

            `Display cursor
            ink 0, 0
            circle mx, my, 2
            line wx + 5 + (306.0/255.0*tempAlpha), wy + 105, wx + 5 + (306.0/255.0*tempAlpha), wy + 124

            `Display final color
            ink rgb(tempRed / 255.0 * tempAlpha, tempGreen / 255.0 * tempAlpha, tempBlue / 255.0 * tempAlpha), 0
            box wx + 5, wy + 130, wx + 78, wy + 203

            sync
         loop

         `Clear image and memblock
         delete image Bin
         delete memblock Bin

      endif
   endif

return

CreateMedia:

   `Create title bar image
   cls
   box 0, 0, 8, 8, Theme, rgb(255, 255, 255), Theme, rgb(255, 255, 255)
   get image GUI, 0, 0, 8, 8, 1

   `Create sprite from it and hide it
   sprite GUI, 0, 0, GUI
   set sprite GUI, 0, 0
   hide sprite GUI

   `Create X button
   cls
   box 0, 0, 6, 6, Theme, rgb(255, 255, 255), Theme, Theme
   ink ThemeTxt, 0
   line 1, 1, 5, 5
   line 1, 4, 5, 0
   get image GUI + 1, 0, 0, 6, 6, 1

   `Create Main HUD
   cls
   box 0, 0, scrX, 50, rgb(255,255,255), Theme, rgb(255,255,255), Theme
   box scrX - 50, 0, scrX, scrY, rgb(255, 255, 255), rgb(255,255,255),Theme,Theme
   `New button
   `up
   box 1, 1, 49, 49, Theme, ThemeBack, Theme, ThemeBack
   ink rgb(255, 255, 255), 0
   box 16, 10, 31, 38
   box 31, 13, 34, 38
   ink rgb(150, 150, 150), 0
   for i = 0 to 3
      line 34 - i, 13 - i, 34 - i, 13
   next i

   `Load button
   `up
   box 51, 1, 99, 49, Theme, ThemeBack, Theme, ThemeBack
   ink rgb(200,135,1), 0
   for i = 0 to 20
      line 61 + (1.0/6*i), 34 - i, 86 + (1.0/6*i), 34 - i
   next i
   ink rgb(255,255,255), 0
   box 63, 15, 87, 33
   ink rgb(248,235,1), 0
   for i = 0 to 18
      line 61 - (1.0/6*i), 34 - i, 86 - (1.0/6*i), 34 - i
   next i

   `Export button
   `up
   box 101, 1, 149, 49, Theme, ThemeBack, Theme, ThemeBack
   ink rgb(150,150,150), 0 : box 110, 9, 135, 39 : box 110, 13, 140, 39
   for i = 0 to 5 : line 135, 8 + i, 135 + i, 8 + i : next i
   ink rgb(200, 200, 200), 0 : box 117, 9, 133, 16
   for i = 0 to 10
      ink rgb(220, 220, 220), 0 : h = sqrt(25 - (i-5)^2) : line 120 + i, 26 - h, 120 + i, 26 + h
      ink rgb(250, 250, 250), 0 : dot 120 + i, 26 - h
   next i
   ink rgb(220, 220, 220), 0 : line 117, 9, 133, 9
   ink rgb(180, 180, 180), 0 : line 110, 9, 116, 9 : line 134, 9, 135, 9
   ink rgb(180, 180, 180), 0 : dot 125, 26

   `Exit button
   `up
   box 151, 1, 199, 49, Theme, ThemeBack, Theme, ThemeBack
   ink rgb(255, 0, 0), 0
   for i = 0 to 26
      line 161 + i, 11 + i, 165 + i, 11 + i
      line 185 - i, 11 + i, 189 - i, 11 + i
   next i

   `*** Create Tool buttons ***
   `pen tool
   `up
   box scrX - 49, 51, scrX - 27, 74, Theme, rgb(255,255,255), Theme, Theme
   ink RGB(128,64,0), 0
   line scrX - 46, 54, scrX - 34, 66 : line scrX - 45, 53, scrX - 33, 65 : line scrX - 47, 55, scrX - 35, 67
   ink RGB(100,50,0), 0
   line scrX - 46, 55, scrX - 35, 66 : line scrX - 45, 54, scrX - 34, 65
   ink RGB(196,98,0), 0
   line scrX - 34, 66, scrX - 31, 69 : line scrX - 33, 65, scrX - 31, 69 : line scrX - 35, 67, scrX - 31, 69
   dot scrX - 35, 66 : dot scrX - 33, 65
   ink 0, 0
   dot scrX - 31, 69

   `Circle shape tool
   `Up
   box scrX - 24, 51, scrX - 1, 74, Theme, rgb(255,255,255), Theme, Theme
   ink 0, 0 : circle scrX - 13, 62, 8

   `Box shape tool
   `Up
   box scrX - 49, 76, scrX - 27, 99, Theme, rgb(255,255,255), Theme, Theme
   ink 0, 0
   line scrX - 46, 83, scrX - 30, 83 : line scrX - 46, 83, scrX - 46, 92
   line scrX - 46, 92, scrX - 31, 92 : line scrX - 31, 92, scrX - 31, 83

   `Fill tool
   `Up
   box scrX - 24, 76, scrX - 1, 99, Theme, rgb(255,255,255), Theme, Theme
   ink rgb(150, 150, 150), 0
   for i = 1 to 5
      line scrX - 12 - i, 86 - i, scrX - 12 - i, 86 + i
      line scrX - 22 + i, 86 - i, scrX - 22 + i, 86 + i
   next i
   ink rgb(230, 230, 230), 0
   line scrX - 21, 86, scrX - 16, 81
   ink rgb(255, 255, 255), 0
   line scrX - 12, 86, scrX - 12, 94
   line scrX - 13, 89, scrX - 13, 93
   line scrX - 11, 88, scrX - 11, 94

   `Line tool
   `Up
   box scrX - 49, 101, scrX - 27, 124, Theme, rgb(255,255,255), Theme, Theme
   ink rgb(0, 0, 0), 0
   line scrX - 46, 104, scrX - 29, 121

   `Zoom Window
   box scrX - 24, 101, scrX - 1, 124, Theme, rgb(255, 255, 255), Theme, Theme
   ink rgb(128,64,0), 0
   line scrX - 21, 121, scrX - 15, 111
   line scrX - 20, 121, scrX - 14, 111
   line scrX - 22, 121, scrX - 16, 111
   ink rgb(150, 150, 150), 0
   circle scrX - 12, 107, 5

   `Spray tool
   box scrX - 49, 126, scrX - 26, 149, Theme, rgb(255, 255, 255), Theme, Theme
   ink rgb(150, 150, 150), 0
   box scrX - 47, 134, scrX - 40, 146
   for i = 1 to 3
      line scrX - 47 + (i*2), 134 - i, scrX - 40, 134 - i
   next i
   ink rgb(200, 200, 200), 0 : box scrX - 40, 130, scrX - 38, 132 : line scrX - 47, 134, scrX - 47, 146
   ink rgb(0, 0, 255), 0 : box scrX - 45, 131, scrX - 43, 133
   ink rgb(255, 255, 255), 0
   dot scrX - 49 + 11, 126 + 4
   line scrX - 49 + 12, 126 + 3, scrX - 49 + 12, 126 + 4
   line scrX - 49 + 13, 126 + 3, scrX - 49 + 13, 126 + 6
   line scrX - 49 + 14, 126 + 2, scrX - 49 + 14, 126 + 3 : dot scrX - 49 + 14, 126 + 5
   dot scrX - 49 + 15, 126 + 2 : dot scrX - 49 + 15, 126 + 7
   dot scrX - 49 + 16, 126 + 4
   dot scrX - 49 + 17, 126 + 1 : dot scrX - 49 + 17, 126 + 7
   dot scrX - 49 + 18, 126 + 3 : dot scrX - 49 + 18, 126 + 9
   dot scrX - 49 + 19, 126 + 7
   dot scrX - 49 + 20, 126 + 1 : dot scrX - 49 + 20, 126 + 5
   dot scrX - 49 + 21, 126 + 9

   `Brush tool
   box scrX - 24, 126, scrX - 1, 149, Theme, rgb(255, 255, 255), Theme, Theme
   ink rgb(255, 255, 255), 0
   box scrX - 20, 128, scrX - 18, 147
   box scrX - 20, 145, scrX - 3, 147

   `RGB color picker
   box scrX - 48, scrY - 270, scrX - 2, scrY - 5, Theme, Theme, rgb(255, 255, 255), rgb(255, 255, 255)
   ink 0, 0
   box scrX - 43, scrY - 265, scrX - 36, scrY - 10
   box scrX - 29, scrY - 265, scrX - 22, scrY - 10
   box scrX - 15, scrY - 265, scrX - 8, scrY - 10

   `Get image
   get image GUI + 2, 0, 0, scrX, scrY, 1
   cls

   `Down - new
   box 0, 0, 48, 48, ThemeBack, Theme, ThemeBack, Theme
   ink rgb(255, 255, 255), 0
   box 15, 10, 30, 38
   box 30, 13, 33, 38
   ink rgb(150, 150, 150), 0
   for i = 0 to 3
      line 33 - i, 13 - i, 33 - i, 13
   next i
   get image GUI + 3, 0, 0, 48, 48, 1

   `down - load
   box 0, 0, 48, 48, ThemeBack, Theme, ThemeBack, Theme
   ink rgb(200,135,1), 0
   for i = 0 to 20
      line 10 + (1.0/6*i), 34 - i, 35 + (1.0/6*i), 34 - i
   next i
   ink rgb(255,255,255), 0
   box 12, 15, 36, 33
   ink rgb(248,235,1), 0
   for i = 0 to 18
      line 10 - (1.0/6*i), 34 - i, 35 - (1.0/6*i), 34 - i
   next i
   get image GUI + 4, 0, 0, 48, 48, 1

   `Down - export
   box 0, 0, 48, 48, ThemeBack, Theme, ThemeBack, Theme
   ink rgb(150,150,150), 0 : box 9, 9, 34, 39 : box 9, 13, 39, 39
   for i = 0 to 5 : line 34, 8 + i, 34 + i, 8 + i : next i
   ink rgb(200, 200, 200), 0 : box 16, 9, 32, 16
   for i = 0 to 10
      ink rgb(220, 220, 220), 0 : h = sqrt(25 - (i-5)^2) : line 19 + i, 26 - h, 19 + i, 26 + h
      ink rgb(250, 250, 250), 0 : dot 19 + i, 26 - h
   next i
   ink rgb(220, 220, 220), 0 : line 16, 9, 32, 9
   ink rgb(180, 180, 180), 0 : line 9, 9, 15, 9 : line 33, 9, 34, 9
   ink rgb(180, 180, 180), 0 : dot 24, 26
   get image GUI + 5, 0, 0, 48, 48, 1

   `down - exit
   box 0, 0, 48, 48, ThemeBack, Theme, ThemeBack, Theme
   ink rgb(255, 0, 0), 0
   for i = 0 to 26
      line 10 + i, 11 + i, 14 + i, 11 + i
      line 34 - i, 11 + i, 38 - i, 11 + i
   next i
   get image GUI + 6, 0, 0, 48, 48, 1

   `down - pen tool
   box 0, 0, 23, 23, Theme, Theme, rgb(255, 255, 255), Theme
   ink RGB(128,64,0), 0
   line 3, 3, 15, 15 : line 4, 2, 16, 14 : line 2, 4, 14, 16
   ink RGB(100,50,0), 0
   line 3, 4, 14, 15 : line 4, 3, 15, 14
   ink RGB(196,98,0), 0
   line 15, 15, 18, 18 : line 16, 14, 18, 18 : line 14, 16, 18, 18
   dot 14, 15 : dot 15, 14
   ink 0, 0
   dot 18, 18
   get image GUI + 7, 0, 0, 23, 23, 1

   `Down - circle tool
   box 0, 0, 23, 23, Theme, Theme, rgb(255, 255, 255), Theme
   ink 0, 0 : circle 11, 11, 8
   get image GUI + 8, 0, 0, 23, 23, 1

   `Down - box tool
   box 0, 0, 23, 23, Theme, Theme, rgb(255, 255, 255), Theme
   ink 0, 0
   line 3, 7, 20, 7 : line 3, 7, 3, 16
   line 3, 16, 20, 16 : line 19, 7, 19, 16
   get image GUI + 9, 0, 0, 23, 23, 1

   `Down - Fill tool
   box 0, 0, 23, 23, Theme, Theme, rgb(255, 255, 255), Theme
   ink rgb(150, 150, 150), 0
   for i = 1 to 5
      line 13 - i, 10 - i, 13 - i, 10 + i
      line 2 + i, 10 - i, 2 + i, 10 + i
   next i
   ink rgb(230, 230, 230), 0
   line 3, 10, 8, 5
   ink rgb(255, 255, 255), 0
   line 12, 10, 12, 18
   line 11, 13, 11, 17
   line 13, 12, 13, 18
   get image GUI + 10, 0, 0, 23, 23, 1

   `Down - line tool
   box 0, 0, 23, 23, Theme, Theme, rgb(255, 255, 255), Theme
   ink 0, 0
   line 3, 3, 20, 20
   get image GUI + 11, 0, 0, 23, 23, 1

   `Down zoom window
   box 0, 0, 23, 23, Theme, Theme, rgb(255, 255, 255), Theme
   ink rgb(128,64,0), 0
   line 2, 20, 8, 10
   line 3, 20, 9, 10
   line 1, 20, 7, 10
   ink rgb(150, 150, 150), 0
   circle 12, 6, 5
   get image GUI + 12, 0, 0, 23, 23, 1

   `Down - spray tool
   box 0, 0, 23, 23, Theme, Theme, rgb(255, 255, 255), Theme
   ink rgb(150, 150, 150), 0
   box 2, 8, 9, 20
   for i = 1 to 3
      line 2 + (i*2), 8 - i, 9, 8 - i
   next i
   ink rgb(200, 200, 200), 0 : box 9, 4, 11, 6 : line 2, 8, 2, 20
   ink rgb(0, 0, 255), 0 : box 4, 5, 6, 7
   ink rgb(255, 255, 255), 0
   dot 11, 4
   line 12, 3, 12, 4
   line 13, 3, 13, 6
   line 14, 2, 14, 3 : dot 14, 5
   dot 15, 2 : dot 15, 7
   dot 16, 4
   dot 17, 1 : dot 17, 7
   dot 18, 3 : dot 18, 9
   dot 19, 7
   dot 20, 1 : dot 20, 5
   dot 21, 9
   get image GUI + 13, 0, 0, 23, 23, 1

   `Down - brush loading tool
   box 0, 0, 23, 23, Theme, Theme, rgb(255, 255, 255), Theme
   ink rgb(255, 255, 255), 0
   box 4, 3, 6, 21
   box 4, 19, 21, 21
   get image GUI + 14, 0, 0, 23, 23, 1

   `+ and - buttons
   box 0, 0, 8, 8, Theme, rgb(255, 255, 255), Theme, Theme
   ink ThemeTxt, 0
   line 4, 1, 4, 7 : line 1, 4, 7, 4
   get image GUI + 15, 0, 0, 8, 8, 1

   box 0, 0, 8, 8, Theme, rgb(255, 255, 255), Theme, Theme
   ink ThemeTxt, 0
   line 1, 4, 7, 4
   get image GUI + 16, 0, 0, 8, 8, 1

   cls

   `Zoom cursor
   ink rgb(255, 255, 255), 0
   box 20, 25, 25, 27
   box 25, 20, 27, 25
   box 27, 25, 32, 27
   box 25, 27, 27, 32
   get image ZoomImg + 1, 0, 0, 50, 50, 1

return

Initialize:

   `Constants
   #constant maxWindows = 20
   #constant GUI = 20
   #constant Canvas = 1
   #constant WindImg = 31
   #constant Bin = 100
   #constant ZoomImg = 101

   #constant BaseDir = get dir$()

   #constant scrX screen width()
   #constant scrY screen height()

   `types
   type window
      x as integer
      y as integer
      sx as integer
      sy as integer
      Cont as integer
      img as integer
   endtype
   type pos
      x as integer
      y as integer
   endtype

   `Arrays
   dim window(0) as window
   dim AFloodFill(-1) as pos

   `Globals
   global ActiveWindow as integer
   ActiveWindow = 1

   global ForRed as integer
   global ForGreen as integer
   global ForBlue as integer
   global ForColor as integer
   ForColor = rgb(ForRed, ForGreen, ForBlue)

   global CTool as integer
   global ZoomWind as integer
   global ToolSize as integer
   ToolSize = 10
   global ToolDensity as integer
   ToolDensity = 20

   `This comes in handy for passing between functions
   global x as integer
   global y as integer
   global sx as integer
   global img as integer
   global imgsx as integer
   global imgsy as integer
   global imgx as integer
   global imgy as integer
   global LastX as integer
   global LastY as integer

   `Setup
   set text font ThemeFont
   set text size 18

   `Create a vector for distances
   r = make vector2(1)

return

`>>>>>>>>>>>>>>>>>>>>>>>>>> NEW - EXPORT - LOAD <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
New:

   `Create new
   ActiveWindow = 0

   `Create window
   size sprite GUI, 200, 8
   paste sprite GUI, 0, 0
   paste image GUI+1, 193, 1
   ink Theme, 0
   box 0, 8, 200, 125
   ink ThemeBack, 0
   box 1, 8, 199, 124
   get image Bin, 0, 0, 200, 150, 1

   `Reset values
   width$ = "0"
   height$= "0"
   CInp = 1
   clear entry buffer

   do

      `Refres
      paste image GUI + 2, 0, 0

      `Handle windows
      Windows = array count(Window(0))
      if Windows > 0
         for w = 1 to Windows
            HandleWindow(w)
         next w
      endif

      `The window
      paste image Bin, (scrX/2) - 100, (scrY/2) - 75

      `Display text
      if CInp = 1 then dwidth$ = width$ + "_" else dwidth$ = width$
      if CInp = 2 then dheight$ =